本文介绍了为 UIImageView 修饰内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我正在尝试实现类似于 Touch Up Inside
和 UIButton
的触摸事件.我见过一些使用 touchesBegan:withEvent
的代码,但看起来我需要在屏幕上滑动一点手指.我其实只是想在图像中触摸
I'm trying to implement touch event similar to a Touch Up Inside
a UIButton
. I've seen some codes using touchesBegan:withEvent
but it looks I need to slide a bit my finger over the screen. I actually just want to touch in the image
代码:
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
NSLog(@"Image touched!");
}
问候!
推荐答案
您可以使用手势来触摸UIImageView
.
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(ClickEventOnImage:)];
[tapRecognizer setNumberOfTouchesRequired:2];
[tapRecognizer setDelegate:self];
//Don't forget to set the userInteractionEnabled to YES, by default It's NO.
myImageView.userInteractionEnabled = YES;
[myImageView addGestureRecognizer:tapRecognizer];
实现ClickEventOnImage
函数.
-(void) ClickEventOnImage:(id) sender
{
}
这篇关于为 UIImageView 修饰内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!