2011-11-24 57 views
14

我有两个UIViewController包含在navigatoin视图控制器中,并且都处于横向模式。我想在两个uiviewcontroller之间切换,而不需要像推动一样的动画。因此,如果用户在第一个视图控制器中单击按钮,我会在这两者之间执行自定义搜索。ios:风景模式下两个视图控制器之间的自定义segue

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

@class AppDelegate; 

@interface NonAnimatedSegue : UIStoryboardSegue { 

} 

@property (nonatomic,assign) AppDelegate* appDelegate; 

@end 

这实现:

#import "NonAnimatedSegue.h" 

@implementation NonAnimatedSegue 

@synthesize appDelegate = _appDelegate; 

-(void) perform{ 
    self.appDelegate = [[UIApplication sharedApplication] delegate]; 
    UIViewController *srcViewController = (UIViewController *) self.sourceViewController; 
    UIViewController *destViewController = (UIViewController *) self.destinationViewController; 
[srcViewController.view removeFromSuperview]; 
[self.appDelegate.window addSubview:destViewController.view]; 
self.appDelegate.window.rootViewController=destViewController; 
} 

@end 

在我切换到定制赛格瑞,实际上它工作正常的脚本中。唯一的问题是第二个uiviewcontroller不是以横向模式显示,而是在protrait中显示。如果我删除自定义的segue并用push segue替换它,则一切正常,第二个viewcontroller以横向模式显示。

那么,如果我使用自定义的segue,那么第二个viewcontroller也处于横向视图中,我该怎么做?

回答

14

上述代码无法正常工作,因为destinationViewController无法从UIInterfaceOrientation自行接收更新。它通过它的“Container View Controller”(导航控制器)接收这些更新。为了使自定义的segue正常工作,我们需要通过导航控制器转换到新的视图。

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

你是一个美丽的人。 –

1

你可以有目的地视图控制器采取中心/从源头控制(这已经是方向正确)变换/界限:

-(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; 
} 
相关问题