[英]UIButton touch up inside event, bounds change?
So, I discovered an interesting behavior of UIButton
after wasting a couple of hours late last night.因此,在昨晚深夜浪费了几个小时之后,我发现了
UIButton
的一个有趣行为。 I probably have come across this in the past but can't recall.我可能在过去遇到过这种情况,但不记得了。 I couldn't find an explanation for this behavior thus far, so please enlighten me if you have any info on this:
到目前为止,我找不到这种行为的解释,所以如果您有任何相关信息,请赐教:
Create an instance of UIButton
, then set its action for UIControlEventTouchUpInside
.创建
UIButton
的实例,然后将其操作设置为UIControlEventTouchUpInside
。 Now, in your running app, press on the button and hold down, move away from the button and notice how it seems like the bounds changed when moving/dragging your finger.现在,在您正在运行的应用程序中,按住按钮并按住不放,离开按钮并注意移动/拖动手指时边界似乎发生了变化。 The touch is recognized quite some distance from the button's original frame, bounds.
触摸被识别为距按钮的原始框架有一段距离,边界。
This caused quite some problems in my app where I implemented code using locationInView: to determine the indexPath of the UITableViewCell
that is the superview of the button.这在我的应用程序中引起了相当多的问题,我使用 locationInView: 来实现代码来确定
UITableViewCell
的 indexPath,它是按钮的超级视图。
My two alternative solutions for determining the indexPath are:我确定 indexPath 的两个替代解决方案是:
Use the buttons superview's superview, which is the UITableViewCell
, together with UITableView's indexPathForCell
: method.使用按钮 superview 的 superview,即
UITableViewCell
和 UITableView 的indexPathForCell
: 方法。
Rather use UIControlEventTouchDown
when specifying my button action.指定我的按钮操作时,请使用
UIControlEventTouchDown
。
Hope someone finds this helpful or can contribute to a solution for the problem.希望有人觉得这很有帮助,或者可以为问题的解决方案做出贡献。
You could use touchesBegan:withEvent.您可以使用 touchesBegan:withEvent。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.