4

我的应用程序中有一个滚动视图,当我滚动到滚动视图的最后一页时,我被绑定到 tableviewcontroller。

但是为了在从滚动视图跳转到表格视图控制器时实现“类似动画的分页”,我扩展了 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 时,我无法让它工作。

我在这里基本上想做的是执行segue,所以看起来tableviewcontroller从左侧进入主屏幕(而不是从顶部或底部,因为它是默认行为),就像上面的代码适用于正常方向一样。我想象的解决方案是这样的:

- (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 回答