发布网友 发布时间:2022-06-13 12:05
共1个回答
热心网友 时间:2023-10-13 08:45
UIScrollView本身无法处理touch事件要想实现,必须对UIScrollView上的subView做touch处理原理十分简单,好比要响应scrollView上的UIImageView,那么请创建一个UIImageVIew的子类,由这个自定义的UIImageView来处理touch事件头文件声明如下,供参考:#import @protocol ImageTouchDelegate-(void)imageTouch:(NSSet *)touches withEvent:(UIEvent *)event whichView:(id)imageView;@end@interface ImageTouchView : UIImageView { id delegate; BOOL delegatrue;}@property(nonatomic,assign)id delegate;@end这个是头文件,源文件可以是这个这样子@implementation ImageTouchView@synthesize delegate;-(id)initWithFrame:(CGRect)frame{ if (self == [super initWithFrame:frame]) { [self setUserInteractionEnabled:YES]; delegatrue=YES; } return self;}- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view{ return YES;}-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ if (delegatrue) { [delegate imageTouch:touches withEvent:event whichView:self]; }