uiviewcontroller – 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中的文本.解除模态时,文本不会调整为原始大小.

解决方法

由于缺乏更好的选择,我已经为此做了一些破解.
基本上在我显示模态视图之前,我拍摄一个屏幕截图并将其放置在呈现视图控制器的顶部.

显然我必须在视图重新出现时删除此屏幕截图

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
  }
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...