我正在尝试实现类似于 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 修饰内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!