码迷,mamicode.com
首页 > 移动开发 > 详细

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

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

标签:ios uiimageview 点击

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直接响应点击事件的解决方法

标签:ios uiimageview 点击

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!