`
zjjzmw1
  • 浏览: 1354631 次
  • 性别: Icon_minigender_1
  • 来自: 开封
社区版块
存档分类
最新评论

UIScrollView的touchesBegan和touchesEnd

    博客分类:
  • iOS
ios 
阅读更多

[iOS Dev] UIScrollView的touchesBegan和touchesEnd

 

touchesBegan跟touchedEnd沒有提供給UIScrollViewDelegate
所以要自己建立一個繼承自UIScrollView的class
重寫這兩個method

▼ myScrollView.h

1
2
@interface myScrollView : UIScrollView
@end

▼ myScrollView.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-(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

1
myScrollView *contentScrollView = [[myScrollView alloc] init];
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics