0
我使用此代码与UISwipeGestureRecognizer方向(左/右)UISwipeGestureRecognizer方向(左/右)与4子视图
两个视图之间滑动,我想做同样的4次:
厂景 - > view2-> view3-> view4
厂景< -view2 < -view3 < -view4
谢谢大家帮忙
//........towards right Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
[cmmtView addGestureRecognizer:rightRecognizer];
[rightRecognizer release];
//........towards left Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[cmmtView addGestureRecognizer:leftRecognizer];
[leftRecognizer release];
和
- (void)leftSwipeHandle:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
// load a different viewController
[cmmtView addSubview:viewCmd2];
} else {
// load an even different viewController
[viewCmd removeFromSuperview];
[viewCmd2 removeFromSuperview];
[viewFocus removeFromSuperview];
[viewWeb removeFromSuperview];
[viewLive removeFromSuperview];
[viewLivePatch removeFromSuperview];
[viewLivePatchConsole removeFromSuperview];}}
- (void)rightSwipeHandle:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
// load a different viewController
[viewCmd2 addSubview:cmmtView];
} else {
// load an even different viewController
[viewCmd removeFromSuperview];
[viewCmd2 removeFromSuperview];
[viewFocus removeFromSuperview];
[viewWeb removeFromSuperview];
[viewLive removeFromSuperview];
[viewLivePatch removeFromSuperview];
[viewLivePatchConsole removeFromSuperview];}}
小问题.... 后4向左扫一个有 ***终止应用程序由于未捕获的异常 'NSRangeException',原因:“*** - [__ NSArrayI objectAtIndex:]:指数4 [0..3]' 我不明白为什么这行不行的... if(self.currentViewIndex> = self.viewArray.count)self.currentViewIndex = self.viewArray.count - 1 ; – jeff
已更新为在获取viewToShow属性之前捕获索引范围。让我知道这是否适合你。 – Logan