Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 自定义分段方向未在横向中使用正确的方向_Xcode_Segue_Uistoryboardsegue_Animatewithduration - Fatal编程技术网

Xcode 自定义分段方向未在横向中使用正确的方向

Xcode 自定义分段方向未在横向中使用正确的方向,xcode,segue,uistoryboardsegue,animatewithduration,Xcode,Segue,Uistoryboardsegue,Animatewithduration,我使用自定义序列在两个视图控制器之间导航。自定义segue使用CGAffineTransformMakeScale在目标控制器上创建缩放效果 当我在纵向模式下运行项目时,一切正常,但当我切换到横向模式时,会出现问题。目标控制器以纵向方向显示在屏幕上,然后以正确的比例(1.0、1.0)设置动画,动画完成后将更改为正确的方向。这对我来说真的很困惑,我在网上找不到关于这个问题的任何信息,所以任何帮助都将不胜感激 我用来测试这一点的项目使用了两个视图控制器,每个视图控制器都有一个触发segue的按钮 这

我使用自定义序列在两个视图控制器之间导航。自定义segue使用CGAffineTransformMakeScale在目标控制器上创建缩放效果

当我在纵向模式下运行项目时,一切正常,但当我切换到横向模式时,会出现问题。目标控制器以纵向方向显示在屏幕上,然后以正确的比例(1.0、1.0)设置动画,动画完成后将更改为正确的方向。这对我来说真的很困惑,我在网上找不到关于这个问题的任何信息,所以任何帮助都将不胜感激

我用来测试这一点的项目使用了两个视图控制器,每个视图控制器都有一个触发segue的按钮

这是我的CustomZoomSegue.m文件:

#import "CustomZoomSegue.h"

@implementation CustomZoomSegue

- (void)perform
{
    UIViewController *destinationViewController = (UIViewController *)self.destinationViewController;
    UIViewController *sourceViewController = (UIViewController *)self.sourceViewController;
    UIWindow *mainWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];

    UIView *sourceView = [sourceViewController view];
    UIView *destinationView = [destinationViewController view];

    destinationView.frame = sourceView.frame;
    [mainWindow addSubview:destinationView];

    [destinationView setAlpha:0.0f];
    [destinationView setTransform:CGAffineTransformMakeScale(0.0, 0.0)];

    // slide newView over oldView, then remove oldView
    [UIView animateWithDuration:0.8
                     animations:^{
                         [destinationView setTransform:CGAffineTransformMakeScale(1.0, 1.0)];
                         [destinationView setAlpha:1.0f];
                     }
                     completion:^(BOOL finished){
                         [destinationView removeFromSuperview];
                         [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                     }];
}

@end

有人知道为什么会这样吗?这让我抓狂

我想问题可能与在显示视图控制器之前设置目标视图的动画有关。控制器涉及视图旋转,但在显示之前不会要求它旋转。我认为,如果您先演示,然后使用源视图和目标视图的图像来制作动画,将获得更好的效果

我通过将目标视图作为子视图添加到源视图中来实现这一点。在我将其直接添加到主窗口之前

以下是在动画块中同时管理缩放和缩放的代码:

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

    [sourceViewController.view addSubview:destinationViewController.view];
    [destinationViewController.view setFrame:sourceViewController.view.window.frame];

    [destinationViewController.view setBounds:sourceViewController.view.bounds];
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    [destinationViewController.view setCenter:CGPointMake(screenSize.width/2 + 127, screenSize.height/2 - 138)];

    [destinationViewController.view setTransform:CGAffineTransformMakeScale(0.0,0.0)];

    [UIView animateWithDuration:1.8
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         [destinationViewController.view setAlpha:0.0];
                         [destinationViewController.view setTransform:CGAffineTransformMakeScale(1.0,1.0)];
                         [destinationViewController.view setAlpha:0.8];
                     }
                     completion:^(BOOL finished){
                         [destinationViewController.view setAlpha:1.0];
                         [destinationViewController.view removeFromSuperview];
                         [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                     }];
}