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