4

アプリにscrollviewがあり、2番目にscrollviewの最後のページにスクロールすると、tableviewcontrollerに移動します。

しかし、scrollviewからtableviewコントローラーにジャンプするときに「アニメーションのようなページング」を実現するために、UIStoryboardSegueクラスを拡張し、次のような実行メソッドを実装しました。

- (void) perform {
    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;

    src.view.transform = CGAffineTransformMakeTranslation(0, 0);
    dst.view.transform = CGAffineTransformMakeTranslation(320, 0);

    [UIView animateWithDuration:0.3
                     animations:^{
                         [src presentModalViewController:dst animated:NO];
                         src.view.transform = CGAffineTransformMakeTranslation(320, 0);
                         dst.view.transform = CGAffineTransformMakeTranslation(0, 0);
                     }
     ];
}

また、ユーザーがUIInterfaceOrientationPortraitオリエンテーションを使用している場合は、チャームのように機能します。しかし、UIInterfaceOrientationLandscapeLeftまたはrightに切り替えると、動作させることができません。

私がここで基本的にやりたいのは、上記のコードが通常の向きで機能するように、テーブルビューコントローラーが左側からメイン画面に(デフォルトの動作であるため、上または下からではなく)入ってくるように見えるようにセグエを実行することです。私は解決策がこのようなものになると想像しました:

- (void) perform {
    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;


    if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft || [[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight){

    }else{
    src.view.transform = CGAffineTransformMakeTranslation(0, 0);
    dst.view.transform = CGAffineTransformMakeTranslation(320, 0);
    }
    [UIView animateWithDuration:0.3
                     animations:^{
                         [src presentModalViewController:dst animated:NO];
                         if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft || [[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight){
                         }else{
                         src.view.transform = CGAffineTransformMakeTranslation(320, 0);
                         dst.view.transform = CGAffineTransformMakeTranslation(0, 0);
                         }
                     }
     ];
}

しかし、私が助けを借りるのはもっと難しいです。

質問の更新:

私は今これを試しました:

- (void) perform {
    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;

    [UIView transitionWithView:src.navigationController.view duration:0.3
                       options:UIViewAnimationTransitionFlipFromRight
                    animations:^{
                        [src.navigationController pushViewController:dst animated:YES];
                     }
     completion:NULL];
}

次のエラーが発生します:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
4

1 に答える 1

2
  1. 幅320をハードコーディングするのではなく、実行時に常に決定する必要があります(例:src.view.frame.size.width)。

  2. 私のデバイスでは、古いビューが点滅しているので、ポートレートのプレゼンテーションに問題がなかったことに驚いています。

  3. あなたの新しい試みは非常に異なった見た目であるように思われます(押すのではなく反転する)。どの効果を目指していますか?

裏返したい場合は、次のようにすることができます。

[UIView animateWithDuration:0.5
                 animations:^{
                     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                     [sourceViewController.navigationController.view addSubview:destinationViewController.view];
                     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:sourceViewController.navigationController.view cache:NO];
                 }
                 completion:^(BOOL finished){
                     [destinationViewController.view removeFromSuperview];
                     [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                 }];

もっとプッシュしたい場合は、通常、フレーム/センターを変更するだけです。たとえば、次のようなことができます。

float width = sourceViewController.navigationController.view.frame.size.width;

CGPoint right = destinationViewController.view.center;
right.x += width;
destinationViewController.view.center = right;

[sourceViewController.navigationController.view addSubview:destinationViewController.view];

[UIView animateWithDuration:0.5
                 animations:^{
                     CGPoint left = sourceViewController.navigationController.view.center;
                     left.x -= width;
                     sourceViewController.navigationController.view.center = left;
                 }
                 completion:^(BOOL finished){
                     [destinationViewController.view removeFromSuperview];
                     [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                 }
 ];
于 2012-06-13T15:40:19.130 に答える