欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

touchesBegan: withEvent: 不执行解决

程序员文章站 2024-02-13 08:21:28
touchesbegan: withevent: / touchesmoved: withevent: / touchesended: withevent: 等只能被uiv...

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