给uiimageview添加手势怎么在触发的方法里拿到这个uiimageview
1个回答
展开全部
给的UIImageView增加点击事件
解决思路1:网友提示在该“button”上增加一个真正的透明button,这样就可以顺利执行点击事件了;但是本人尝试发现,如果我调整了button的透明度后,点击是没有效果的!可能是我操作错误,待再次验证。
解决思路2:为的UIImageView增加手势
[ImageView的addGestureRecognizer:我们自己的手势识别 ]
如何创建一个手势?看看UITapGestureRecognizer的用法吧
//单指单击
UITapGestureRecognizer * singleFingerOne = [[UITapGestureRecognizer页头] initWithTarget:自
操作:@selector(handleSingleFingerEvent :)]
singleFingerOne.numberOfTouchesRequired = 1; //手指数
singleFingerOne.numberOfTapsRequired = 1; //抽头次数
singleFingerOne 委托 =自我;
//单指双击
UITapGestureRecognizer * singleFingerTwo = [[UITapGestureRecognizer页头] initWithTarget:自
操作:@selector(handleSingleFingerEvent :)];
singleFingerTwo.numberOfTouchesRequired = 1;
singleFingerTwo.numberOfTapsRequired = 2;
。singleFingerTwo 委托 =自我;
//双指单击
UITapGestureRecognizer * doubleFingerOne = [[UITapGestureRecognizer页头] initWithTarget:自
操作:@selector(handleDoubleFingerEvent :)];
doubleFingerOne.numberOfTouchesRequired = 2;
doubleFingerOne.numberOfTapsRequired = 1;
。doubleFingerOne 委托 =自我;
UITapGestureRecognizer * doubleFingerTwo = [[UITapGestureRecognizer页头] initWithTarget:自
操作:@selector(handleDoubleFingerEvent :)];
doubleFingerTwo.numberOfTouchesRequired = 2;
doubleFingerTwo.numberOfTapsRequired = 2;
。doubleFingerTwo 委托 =自我;
//如果不加下面的话,当单指双击时,会先调用单指单击中的处理,再调用单指双击中的处理
[singleFingerOne requireGestureRecognizerToFail:singleFingerTwo]
//同理双指亦是如此
[doubleFingerOne requireGestureRecognizerToFail:doubleFingerTwo]
[self.view addGestureRecognizer:singleFingerOne]
[self.view addGestureRecognizer:singleFingerTwo]
[self.view addGestureRecognizer:doubleFingerOne]
[self.view addGestureRecognizer:doubleFingerTwo]
[singleFingerOne发布]
[singleFingerTwo发布]
[doubleFingerOne发布]
[doubleFingerTwo发布]
处理事件的方法,代码:
//处理单指事件
- (无效)handleSingleFingerEvent:(UITapGestureRecognizer *)发件人
{
如果(sender.numberOfTapsRequired == 1){
//单指单击
的NSLog(@“单指单击”);
} 否则如果(sender.numberOfTapsRequired == 2){
//单指双击
的NSLog(@“单指双击”);
}
}
//处理双指事件
- (无效)handleDoubleFingerEvent:(UITapGestureRecognizer *)发件人
{
如果(sender.numberOfTapsRequired == 1){
//双指单击
的NSLog(@“双指单击”);
} 否则如果(sender.numberOfTapsRequired == 2){
//双指双击
的NSLog(@“双指双击”);
}
}
解决思路1:网友提示在该“button”上增加一个真正的透明button,这样就可以顺利执行点击事件了;但是本人尝试发现,如果我调整了button的透明度后,点击是没有效果的!可能是我操作错误,待再次验证。
解决思路2:为的UIImageView增加手势
[ImageView的addGestureRecognizer:我们自己的手势识别 ]
如何创建一个手势?看看UITapGestureRecognizer的用法吧
//单指单击
UITapGestureRecognizer * singleFingerOne = [[UITapGestureRecognizer页头] initWithTarget:自
操作:@selector(handleSingleFingerEvent :)]
singleFingerOne.numberOfTouchesRequired = 1; //手指数
singleFingerOne.numberOfTapsRequired = 1; //抽头次数
singleFingerOne 委托 =自我;
//单指双击
UITapGestureRecognizer * singleFingerTwo = [[UITapGestureRecognizer页头] initWithTarget:自
操作:@selector(handleSingleFingerEvent :)];
singleFingerTwo.numberOfTouchesRequired = 1;
singleFingerTwo.numberOfTapsRequired = 2;
。singleFingerTwo 委托 =自我;
//双指单击
UITapGestureRecognizer * doubleFingerOne = [[UITapGestureRecognizer页头] initWithTarget:自
操作:@selector(handleDoubleFingerEvent :)];
doubleFingerOne.numberOfTouchesRequired = 2;
doubleFingerOne.numberOfTapsRequired = 1;
。doubleFingerOne 委托 =自我;
UITapGestureRecognizer * doubleFingerTwo = [[UITapGestureRecognizer页头] initWithTarget:自
操作:@selector(handleDoubleFingerEvent :)];
doubleFingerTwo.numberOfTouchesRequired = 2;
doubleFingerTwo.numberOfTapsRequired = 2;
。doubleFingerTwo 委托 =自我;
//如果不加下面的话,当单指双击时,会先调用单指单击中的处理,再调用单指双击中的处理
[singleFingerOne requireGestureRecognizerToFail:singleFingerTwo]
//同理双指亦是如此
[doubleFingerOne requireGestureRecognizerToFail:doubleFingerTwo]
[self.view addGestureRecognizer:singleFingerOne]
[self.view addGestureRecognizer:singleFingerTwo]
[self.view addGestureRecognizer:doubleFingerOne]
[self.view addGestureRecognizer:doubleFingerTwo]
[singleFingerOne发布]
[singleFingerTwo发布]
[doubleFingerOne发布]
[doubleFingerTwo发布]
处理事件的方法,代码:
//处理单指事件
- (无效)handleSingleFingerEvent:(UITapGestureRecognizer *)发件人
{
如果(sender.numberOfTapsRequired == 1){
//单指单击
的NSLog(@“单指单击”);
} 否则如果(sender.numberOfTapsRequired == 2){
//单指双击
的NSLog(@“单指双击”);
}
}
//处理双指事件
- (无效)handleDoubleFingerEvent:(UITapGestureRecognizer *)发件人
{
如果(sender.numberOfTapsRequired == 1){
//双指单击
的NSLog(@“双指单击”);
} 否则如果(sender.numberOfTapsRequired == 2){
//双指双击
的NSLog(@“双指双击”);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询