iOS开发中touchesBegan和touchesEn…「建议收藏」

2022-09-15 10:13:04 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

touchesBegan 跟 touchedEnd 沒有提供給 UIScrollViewDelegate

所以要自己建立一個繼承自 UIScrollView 的 class

重寫這兩個 method

myScrollView.h

@interface myScrollView : UIScrollView

@end

myScrollView.m

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

[super touchesBegan:touches withEvent:event];

if ( !self.dragging )

{

[[self nextResponder] touchesBegan:touches withEvent:event];

}

}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

[super touchesEnded:touches withEvent:event];

if ( !self.dragging )

{

[[self nextResponder] touchesEnded:touches withEvent:event];

}

}

之後建立 UIScrollView 就是用 myScrollView 建立 即可使用這兩個 method

myScrollView *contentScrollView = [[myScrollView alloc] init];

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164168.html原文链接:https://javaforall.cn

0 人点赞