当前位置: 移动技术网 > 移动技术>移动开发>IOS > touchesBegan: withEvent: 不执行解决

touchesBegan: withEvent: 不执行解决

2019年07月24日  | 移动技术网移动技术  | 我要评论

touchesbegan: withevent: / touchesmoved: withevent: / touchesended: withevent: 等只能被uiview捕获(如有问题请指出对请指出,路过的大牛请勿喷),当我们创建

uiscrollview uiimageview 时,当点击时uiscrollview uiimageview 会截获touch事件,导致touchesbegan: withevent:/touchesmoved: withevent:/touchesended: withevent: 等方法不执行。解决办法:当uiscrollview 或 uiimageview 截获touch事件后,让其传递下去即可(就是传递给其父视图uiview)

可以通过写uiscrollview 或 uiimageview 的category 重写touchesbegan: withevent: / touchesmoved: withevent: / touchesended: withevent: 等来实现

// 
// uiscrollview+uitouch.m 
//  
// 
// created by mls on 15/11/20. 
// copyright © 2015年 mls. all rights reserved. 
// 
 
#import "uiscrollview+uitouch.h" 
 
@implementation uiscrollview (uitouch) 
 
- (void)touchesbegan:(nsset<uitouch *> *)touches withevent:(uievent *)event 
{ 
  // 选其一即可 
  [super touchesbegan:touches withevent:event]; 
//  [[self nextresponder] touchesbegan:touches withevent:event]; 
} 
 
@end 




如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网