0

スワイプしたい3つのviewControllerの配列を作成しました。画面全体にアニメーションを表示します。

これまでのところ、ビューの配列を作成し、ジェスチャ コントロールを使用して、配列の最初のビューを、アニメーションを保持している viewController の viewDidLoad メソッドのビューにロードしています。

私が行ったことは、viewController オブジェクト (current、furutre) に追加されます。アプリが最初に読み込まれるときに、配列の最初のビューを現在の viewController に配置します。次に、ビューをスワイプすると、配列に次のビューを読み込みます。将来のviewcontrollerとアニメーションを実行します..次に、3番目のアニメーションに対して同じことを行います..しかし、最後のアニメーションの前に2番目のビューを現在に渡し、次に3番目のビューを未来に渡していないため、壊れています..(これがうまくいくことを願っています検出。)

これまでに行ったことを実行しているコードは次のとおりです..

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.title = @"Prototype";
    //Initalizse the swipe gestuer listener
    [self setupLeftSwipeGestureRecognizer];
    [self setupRightSwipeGestureRecognizer];

    //Initalize all of the swipe views
    DetailViewController *DVCA = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
    DetailViewControllerB *DVCB = [[DetailViewControllerB alloc] initWithNibName:@"DetailViewControllerB" bundle:[NSBundle mainBundle]];
    DetailViewControllerC *DVCC = [[DetailViewControllerC alloc] initWithNibName:@"DetailViewControllerC" bundle:[NSBundle mainBundle]];

    //Assinge swipeviews to viewArray
    viewArray = [NSArray arrayWithObjects:DVCA, DVCB, DVCC, nil];

    //Initalize viewcount so it can keep track of which viewController is in view
    viewCount = 0;

    // set detail View as first view 
    currentViewController = [viewArray objectAtIndex:viewCount];
    [self.view addSubview:currentViewController.view];

}


// Need to change this to work with viewArray
- (void)swipedScreen:(UISwipeGestureRecognizer*)gesture {

    //Left swipe
    if (gesture.direction == UISwipeGestureRecognizerDirectionLeft) {

        //stops swipes from returning any viewCount outside of viewArrays range
        if ((viewCount >= 0) || (viewCount >= 2)) {
            //Increment for next view
            viewCount += 1;

            futureViewController = [viewArray objectAtIndex:viewCount];
            [self.view addSubview:futureViewController.view];
            [futureViewController.view setFrame:CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height)];

            [UIView animateWithDuration:0.25 animations:^{
                [futureViewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
                [currentViewController.view setFrame:CGRectMake(-320, 0, self.view.frame.size.width, self.view.frame.size.height)];
            }];

        }

    }
    //Right swipe -- still need to do this (go back through the view array.
    else if (gesture.direction == UISwipeGestureRecognizerDirectionRight){

        [UIView animateWithDuration:0.25 animations:^{
            [self.detailViewA.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
            [self.detailViewB.view setFrame:CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height)];
        }];

    }
}
4

1 に答える 1

0

申し訳ありませんが、ビューコントローラのビューを切り替えるにはUInavigationControllerを使用する必要があります。フレームをアニメートすることはできますが、uinavigationcontrolllerに含まれているクラシックアニメーションは使用できません。ナビゲーションコントローラーでビューコントローラーを押してポップします。アップルのドキュメントでUINavigationControllerを探してください。コードで回避しようとしているのであれば、ナビゲーションバーを上部に配置する必要はありません。

于 2012-05-31T07:47:38.977 に答える