8

在iOS 8上,我對導航欄和方向更改有奇怪的行爲。iOS 8:在縱向上呈現模態視圖控制器會導致底層橫向導航控制器導航欄的大小調整

我有一個導航控制器,它報告支持的接口方向UIInterfaceOrientationMaskLandscapeRight。導航欄有橫向的預期高度(可惜我無權發佈截圖)。

然後我發起一個視圖控制器的模態演示,該控制器只支持UIInterfaceOrientationMaskPortrait。當演示動畫開始時,底層導航控制器的度量標準似乎會更改爲肖像演示文稿,因爲導航欄的高度會增加到其縱向大小,如上所述。

iOS 7不顯示此行爲。我錯過了什麼?我想恢復舊的行爲。

這裏是上面的簡單例子的全碼:

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 


    DOGButtonViewController *root = [DOGButtonViewController new]; 
    DOGOrientedNavigationController *navi = [[DOGOrientedNavigationController alloc] initWithRootViewController:root]; 
    navi.allowedInterfaceOrientations = UIInterfaceOrientationMaskLandscapeRight; 

    self.window.rootViewController = navi; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait; 
} 

@end 


@implementation DOGOrientedNavigationController 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return self.allowedInterfaceOrientations; 
} 

@end 

@implementation DOGButtonViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.title = @"Button View Controller"; 
} 

- (BOOL)prefersStatusBarHidden 
{ 
    return YES; 
} 

- (IBAction)buttonClicked:(id)sender 
{ 
    DOGPortraitViewController *vc = [DOGPortraitViewController new]; 
    [self presentViewController:vc animated:YES completion:nil]; 
} 

@end 

@implementation DOGPortraitViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.title = @"Portrait Title"; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (IBAction)buttonClicked:(id)sender 
{ 
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 
} 

- (BOOL)prefersStatusBarHidden 
{ 
    return YES; 
} 

@end 

在一個更復雜的設置我也遇到包含在導航控制器一個UIWebView文本呈現所述肖像模式時被放大。在解除模式時,文本不會調整爲原始大小。

+0

你設法找到解決這個刪除此屏幕截圖?我遇到同樣的事情 – 2014-10-03 20:17:43

+0

不幸的是,但我會在即將到來的日子裏研究這一點。 – thewulf 2014-10-06 07:25:28

+0

這裏也有類似的問題。它看起來像呈現視圖控制器也旋轉(雖然它不應該) – Carlos 2015-05-05 18:01:25

回答

0

由於缺乏更好的選擇,我對此做了一些修改。 基本上,在我展示模態視圖之前,我會拍攝一個屏幕截圖並將其放置在呈現視圖控制器的頂部。

很顯然,我有當的觀點再次出現

func showScreenShot() { 
    let image = screenShot() 
    self.screenShotImageView = UIImageView(image: image) 
    self.view.addSubview(self.screenShotImageView!) 
    } 

func screenShot() -> UIImage { 
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, true, UIScreen.mainScreen().scale) 
    self.view.layer.renderInContext(UIGraphicsGetCurrentContext()) 
    let image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return image 
} 

func removeScreenShot() { 
    if let screenImageView = self.screenShotImageView { 
    screenImageView.removeFromSuperview() 
    self.screenShotImageView = nil 
    } 
} 
相關問題