iOS:触摸Imageview时发生的事件 [英] IOS: event when an Imageview is touched
本文介绍了iOS:触摸Imageview时发生的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带png的ImageView,我想这样做:当有人触摸此imageview时,其alpha更改为0.0,这可能吗?(全部不带按钮)
I have an ImageView with a png and I want to do this: when someone touch this imageview it's alpha change to 0.0, is it possible? (all without buttons)
推荐答案
是的,有可能.例如,您可以按照以下步骤进行操作:
Yes, it is possible. For example you can do that with following steps:
- 将图像视图的userInteractionEnabled属性设置为YES-这样它将接收触摸事件
- 向其中添加UITapGestureRecongnizer
-
在手势处理程序中将视图的Alpha设置为0.0,您也可以使用动画来做到这一点:
- set image view's userInteractionEnabled property to YES - so it will receive touch events
- add UITapGestureRecongnizer to it
in gesture handler set view's alpha to 0.0, you can do that with animation as well:
[UIView animateWithDuration:0.5 animations:^(void){
imageView.alpha = 0.0f;
}];
这篇关于iOS:触摸Imageview时发生的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文