我有一个带有PNG的ImageView,我想这样做:当有人触摸这个imageview时,它的alpha变化为0.0,有可能吗? (全部没有按钮)iOS:触摸Imageview时发生的事件
4
A
回答
5
是的,这是可能的。例如,你可以做到这一点下面的步骤:
- 集图像视图的userInteractionEnabled属性是 - 所以它会接收触摸事件
- 添加UITapGestureRecongnizer它
手势处理程序中设置视图的alpha为0.0,你可以做到这一点的动画,以及:
[UIView animateWithDuration:0.5 animations:^(void){ imageView.alpha = 0.0f; }];
3
已经有很多像这样的问题。与谷歌搜索给了我的情况如下:
14
可以使用UITapGestureRecognizer
加到UIImageView
通过addGestureRecognizer
片段:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTaped:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
[iv addGestureRecognizer:singleTap];
[iv setUserInteractionEnabled:YES];
和
- (void)imageTaped:(UIGestureRecognizer *)gestureRecognizer {
[UIView animateWithDuration:0.5 animations:^(void){
imageView.alpha = 0.0f;
}];
}
1
斯威夫特
的代码对我来说,我实现了双击手势的图像点击
1 - 通过拖动将图像链接到ViewController d删除
@IBOutlet weak var imgCapa: UIImageView!
2 - 实例UITapGestureRecognizer在viewDidLoad方法:
override func viewDidLoad() {
super.viewDidLoad()
//instance the UITapGestureRecognizer and inform the method for the action "imageTapped"
var tap = UITapGestureRecognizer(target: self, action: "imageTapped")
//define quantity of taps
tap.numberOfTapsRequired = 1
tap.numberOfTouchesRequired = 1
//set the image to the gesture
imgCapa.addGestureRecognizer(tap)
}
3 - 创建做你想要当图像点击
func imageTapped(){
//write your specific code for what do you want
//in my case I want to show other page by specific segue
let sumario = self.storyboard?.instantiateViewControllerWithIdentifier("sumarioViewController") as SumarioViewController
self.performSegueWithIdentifier("segueSumarioViewController", sender: sumario)
}
0
在最近的Xcode什么方法,这很容易。进入故事板,在对象库中搜索“手势”,将想要的图像拖到图像视图上。然后,您可以将视图层次结构中的手势对象视为点击事件,即通过控件拖动到您的视图控制器来连接事件处理程序。
一旦你可以设置alpha,只要你喜欢,但如果你试图从根本上删除图像视图,你应该设置imageView.hidden = true
/imageView.hidden = YES
,因为这会阻止它接收事件。
相关问题
- 1. 触摸事件ImageView + GLSurfaceView
- 2. 与触摸事件移动imageview的
- 3. 如何获得的ImageView触摸事件回的ImageView父活动
- 4. 如何获取ImageView带来ImageView的触摸事件?
- 5. iOS中的记录触摸事件
- 6. 硬件相机触摸事件ios
- 7. 如何防止在Android中刷卡时发生触摸事件?
- 8. iOS的触摸事件(触摸收盘没有在合适的时间调用)
- 9. 如何触发触摸事件?
- 10. 用触摸设备触发mousewheel事件
- 11. 识别触发触摸事件
- 12. 触摸事件(onClickListener)不触发recyclerView
- 13. 未触发触摸和滑动事件
- 14. 触摸事件
- 15. UIContainerView事件后未响应触摸iOS
- 16. 在ios中连接触摸事件
- 17. 只将触摸事件转发给正在触摸的视图
- 18. 使用触摸事件在imageView中进行连续触摸检测..?
- 19. 触发iOS上的触摸标注/ android
- 20. UITabBarItem不产生触摸事件
- 21. 如何获得触摸事件发生的信息以及哪种触摸事件并未处理?
- 22. 如何处理缩放的ImageView的触摸事件?
- 23. 事件触摸屏轻轻触摸
- 24. 触摸开始事件是否会触发点击事件?
- 25. iOS 8手机safari错误的触摸事件时间戳
- 26. MKMapView触摸事件
- 27. UIImageView触摸事件
- 28. Recyclerview触摸事件
- 29. UIwebview触摸事件
- 30. UIWebView addSubview:UIImageView在触摸事件触发时不显示
为什么要消除按钮?您可以修改它们的属性,使它们看起来完全像图像,同时保留使用按钮获得的所有功能。 –
[我如何检测UIImageView的触摸事件](http:// stackoverflow。COM /问题/ 855095 /如何-可以-I-检测最触摸事件的-AN-的UIImageView) – vikingosegundo