首页 > 移动平台 > 详细

IOS UIImageView直接响应点击事件的解决方法

时间:2015-04-17 18:34:29      阅读:351      评论:0      收藏:0      [点我收藏+]

UIImageView的手势处理可以响应点击事件。

  1.  self.allScreenImg.userInteractionEnabled = YES;//UIImageView默认不响应手势,需要开启userInteractionEnabled

    //处理单击事件

    UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAllScreen:)];

    [self.allScreenImg addGestureRecognizer:singleTap];


2. 添加处理的方法

- (void) clickAllScreen:(UITapGestureRecognizer *) recognizer {

    AllScreenViewController* recordViewController = [[AllScreenViewController alloc] initWithStoryboard];

    [self.navigationController pushViewController:recordViewController animated:YES];

}


以上操作即可以响应了UIImageView的点击事件了。

方法二:

为UIImageView设置tag,直接处理手势 以处理单击事件:

    imageView.setTag = 333;

   -(void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event {

        UIImageView* img = (UIImageView *) [self.view viewWithTag: 333];

        if (img) {

            // TODO some thing

        }

    }




 参考博文:  http://www.tekuba.net/program/274/

    


本文出自 “羊仔” 博客,请务必保留此出处http://5934497.blog.51cto.com/5924497/1633896

IOS UIImageView直接响应点击事件的解决方法

原文:http://5934497.blog.51cto.com/5924497/1633896

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!