objective-c – 在试图切断时旋转被破坏

我在我的应用程序中有一个scrollview,第二个滚动到我的scrollview的最后一页我被segued到tableviewcontroller.

但是为了在从scrollview跳转到tableview控制器时实现“像动画一样分页”,我扩展了UIStoryboardSegue类并实现了如下的perform方法:

- (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或者右边时,我无法让它工作.

我在这里基本上想要做的是执行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'

最佳答案 >而不是硬编码宽度320,你应该总是在运行时确定,例如src.view.frame.size.width.

>我很惊讶你对画像的表现很满意,就像在我的设备上一样,旧视图眨了眨眼.

>似乎你的新尝试是一个非常不同的外观(翻转而不是推动).你想要哪种效果?

如果你想翻转,你可以这样做:

[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];
                 }
 ];
点赞