为 UIImageView 修饰内部

Touch Up Inside for a UIImageView(为 UIImageView 修饰内部)

本文介绍了为 UIImageView 修饰内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现类似于 Touch Up InsideUIButton 的触摸事件.我见过一些使用 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 修饰内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:为 UIImageView 修饰内部

基础教程推荐