简体   繁体   English

如何以编程方式点击UIImageView在iPhone上做点什么?

[英]How do I programmatically make clicking on a UIImageView do something on the iPhone?

I have programmatically added a UIImageView. 我已经以编程方式添加了UIImageView。 How do I make it send a message to my controller when the users clicks it, sending itself as the only parameter? 当用户点击它时,如何让它向我的控制器发送消息,将自己作为唯一参数发送?

I wouldn't use a UIImageView unless there was some other compelling reason. 除非有其他令人信服的理由,否则我不会使用UIImageView。 I'd just use a custom UIButton and use the UIImage as its background. 我只使用自定义UIButton并使用UIImage作为其背景。

  1. Create a new class that extends UIImageView and use that. 创建一个扩展UIImageView并使用它的新类。
  2. In your class, override the touch events - touchesBegan, touchesEnded and/or touchesMoved as appropriate 在您的课程中,根据需要覆盖触摸事件 - touchesBegan,touchesEnded和/或touchesMoved
  3. From those methods, call back to a method on the controller. 从这些方法中,回调控制器上的方法。

I'd just put a custom button over the UIImage view, and use normally - buttons with Custom style are invisible and so will not obscure the image. 我只是在UIImage视图上放置一个自定义按钮,并且正常使用 - 具有自定义样式的按钮是不可见的,因此不会遮挡图像。 It's also a great way to turn regions of text into clickable areas as well. 这也是将文本区域转换为可点击区域的好方法。

Or, you could assign the custom image as a graphic background for the button. 或者,您可以将自定义图像指定为按钮的图形背景。

just put a button over the imageview, with the Alpha attribute set to 0.10 or less. 只需在imageview上放一个按钮,Alpha属性设置为0.10或更小。 you can capture the button's tap event but almost cannot see it. 你可以捕捉按钮的点击事件,但几乎看不到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone编程:如何在实际大小的UIImageView节目中制作UIImage? - iPhone programming: How do I make a UIImage in a UIImageView show at actual size? iPhone我如何在UITableView / UIImageView中做多列 - iPhone how i can I do multiple columns in UITableView/UIImageView 如何以编程方式或在情节提要中将UIImageView居中 - How do I center a UIImageView either programmatically or in the storyboard 如何从以编程方式创建的UIImageView中选择 - How do I segue from programmatically created UIImageView 如何使用 iPhone UIImageView 链接缩放动画? - How do I chain scale animations with an iPhone UIImageView? 如何在iPhone SDK的UIImageView中为区域着色? - How do I color an area in UIImageView in iPhone SDK? 我如何获取iPhone状态栏放在UIImageView的顶部 - How do I get the iPhone status bar to lay atop a UIImageView 如何通过编程方式单击iPhone上的按钮进行查看? - How to make a view by clicking a Button on iPhone programmatically? 如何以编程方式将UIImage添加到UIImageView然后将该UIImageView添加到另一个UIView? - How do I programmatically add a UIImage to a UIImageView then add that UIImageView to another UIView? 如何在iPhone上的OpenGL中执行补间动画? - How do I do something like a motion tween in OpenGL on the iPhone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM