ios:横向模式下两个ViewController之间的自定义分段

ios:横向模式下两个ViewController之间的自定义分段,ios,uiviewcontroller,push,Ios,Uiviewcontroller,Push,我有两个UIViewController,它们包含在导航视图控制器中,并且都处于横向模式。我想在两个uiviewcontroller之间切换,而不需要类似推送的动画。因此,如果用户在第一个viewcontroller中单击一个按钮,我将在这两者之间执行一个自定义分段 #import <Foundation/Foundation.h> #import "AppDelegate.h" @class AppDelegate; @interface NonAnimatedSegue :

我有两个UIViewController,它们包含在导航视图控制器中,并且都处于横向模式。我想在两个uiviewcontroller之间切换,而不需要类似推送的动画。因此,如果用户在第一个viewcontroller中单击一个按钮,我将在这两者之间执行一个自定义分段

#import <Foundation/Foundation.h>
#import "AppDelegate.h"

@class AppDelegate;

@interface NonAnimatedSegue : UIStoryboardSegue {

}

@property (nonatomic,assign) AppDelegate* appDelegate;

@end
在情节提要中,我切换到了自定义segue,实际上效果很好。唯一的问题是,第二个uiviewcontroller不是以横向模式显示,而是以protrait模式显示。如果我删除自定义segue并用推式segue替换它,则一切正常,第二个viewcontroller以横向模式显示


那么,如果我使用自定义segue,我必须做什么才能使第二个viewcontroller也在横向视图中呢?

上面的代码不起作用,因为destinationViewController无法单独从UIInterfaceOrientation接收更新。它通过“容器视图控制器”(导航控制器)接收这些更新。为了让自定义segue正常工作,我们需要通过导航控制器转换到新视图

-(void) perform{
    [[[self sourceViewController] navigationController] pushViewController:[self destinationViewController] animated:NO];
}

您可以让目标视图控制器从源控制器(已正确定向)获取中心/变换/边界:

-(void) perform{
    [[[self sourceViewController] navigationController] pushViewController:[self destinationViewController] animated:NO];
}
-(void) perform{
    self.appDelegate = [[UIApplication sharedApplication] delegate];
    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;

// match orientation/position
dst.view.center = src.view.center;
dst.view.transform = src.view.transform;
dst.view.bounds = src.view.bounds;

[dst.view removeFromSuperview];
[self.appDelegate.window addSubview:dst.view];
self.appDelegate.window.rootViewController=dst;
}