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