iPhone:调整 UIImageView 的大小不会调整“触摸区域”的大小;
我有一个 UIImageView。在 IB 中,我在此 UIImageView 上附加了一个“Touch Up”事件,以在我的代码中调用 IBAction。这一切都很好。
在某些情况下,我需要在代码中调整此 UIImageView 的大小。我通过设置它的“frame”属性来做到这一点。调整大小效果很好。问题在于“触摸区域”保持原始大小。
我的意思是,假设我从 100x100 的 UIImageView 开始:
***
***
***
然后将其大小调整为 200x100:
***xxx
***xxx
***xxx
在这种情况下,UIImageView 显示在整个区域(* 和 x)中,但触摸仅在原始区域中响应(由 * 表示) )。
我怎样才能调整响应触摸事件的区域的大小?
编辑:我还应该提到,我也移动了 UIImageView 的原点,以防产生影响。
I have a UIImageView. In IB I attached a 'Touch Up' event on this UIImageView to call an IBAction in my code. This all works fine.
In some cases I need to resize this UIImageView in my code. I do this by settings it's 'frame' property. The resizing works fine. The problem is that the 'touch area' stayed the original size.
What I mean is that let's say I start with a UIImageView of 100x100:
***
***
***
Then resize it to 200x100:
***xxx
***xxx
***xxx
In this case the UIImageView shows up in the entire area (* and x) but the touches only respond in the original area (represented by *).
How can I also resize the area that responds to touch events?
EDIT: I should also mention that I move the UIImageView's origin as well, in case that makes a difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
呃不,不是。 Touch up 事件只能发送到
UIControl
子类,而UIImageView
则不然。所以我认为你很困惑,你的观点可能比你想象的要多。您是否可能在图像顶部添加了一个忘记调整大小的透明按钮?
请注意,如果您需要“图像按钮”行为,您还可以将
UIButton
与图像集一起使用。Uhhh no it does not. Touch up events can only be sent to
UIControl
subclasses, whichUIImageView
is not.So I think you are confused and you might have more views than you think. Have you maybe added a transparent button on top of your image that you forgot to resize?
Note that you can also use a
UIButton
with an image set if you need 'image button' behaviour.