【问题标题】:Rotatation broken while trying to segue尝试转接时旋转中断
【发布时间】:2012-06-13 13:24:06
【问题描述】:

我的应用中有一个滚动视图,当我滚动到滚动视图的最后一页时,我会被绑定到 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'

【问题讨论】:

    标签: objective-c ios ios5 orientation segue


    【解决方案1】:
    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];
                     }
     ];
    

    【讨论】:

    • 第二部分在我看来不错,有点像从右侧翻转新的视图控制器。
    猜你喜欢
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    相关资源
    最近更新 更多