【发布时间】:2011-07-01 20:10:23
【问题描述】:
我有一个全屏尺寸的 UIScrollView(iPad,1024x768,横向模式)。所以我需要识别用两根手指向任何方向滑动。这就是我所拥有的(mainScroll 是我班级的财产):
//MyViewController.h
- (void)loadView {
mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
mainScroll.contentSize = CGSizeMake(1024*pageNumber, 768);
mainScroll.pagingEnabled = YES;
mainScroll.delegate = self;
[self.view addSubview:mainScroll];
GestureRecognizer *tapInterceptor = [[GestureRecognizer alloc] init];
tapInterceptor.numberOfTouchesRequired = 2;
tapInterceptor.direction = UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
[mainScroll addGestureRecognizer:tapInterceptor];
mainScroll.userInteractionEnabled = YES;
}
和
//GestureRecognizer.h
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if ([touches count] > 1)
NSLog(@"Started");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if ([touches count] > 1)
NSLog(@"Moved");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([touches count] > 1)
NSLog(@"Ended");
}
我必须添加条件
if ([touches count] > 1)
因为它不仅适用于两次(或更多)触摸,也适用于一次。
但滑动(两次触摸)仍在滚动我的 UIScrollView。我该如何预防?那么如何在不影响滚动视图的情况下识别滑动呢?
【问题讨论】:
-
那么您的编程问题是什么?要具体。
-
问题是:如何识别滑动而不影响滚动视图?
标签: objective-c xcode ipad uiscrollview multi-touch