2 alllllllll alllllllll 于 2013.06.17 13:55 提问

UIImageView的触控事件

下面这段代码显示图片:

UIImageView *preArrowImage =[[UIImageView alloc]init ];
preArrowImage.image =[UIImage imageNamed:@"arrowprev.png"];
preArrowImage.frame = CGRectMake(20, 60, 10, 30);
[self.view addSubview:preArrowImage];

想要对preArrowImage 的触控事件进行一些操作,怎么实现?

2个回答

zhanglei5415
zhanglei5415   Rxr 2013.06.17 15:13
已采纳

给preArrowImage添加tap 手势

UITapGestureRecognizer *recognizer=[[UITapGestureRecognizer alloc]
                                      initWithTarget:self action:@selector(tapHandler:)];
        [preArrowImage addGestureRecognizer:recognizer];


-(void)tapHandler:(UITapGestureRecognizer *)recognizer {
     //...to do your logic
}
Chengzi_963
Chengzi_963   2013.06.17 15:22

在图片添加UITapGesture,然后启用UserInteraction

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self 
action:@selector(singleTapGestureCaptured:)];
[preArrowImage addGestureRecognizer:singleTap];
[preArrowImage setMultipleTouchEnabled:YES];
[preArrowImage setUserInteractionEnabled:YES];
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!