iOS 9:在 UINavigationController pushViewController 之后不再在 viewWillAppear 中设置框架 [英] iOS 9: Frame no longer set in viewWillAppear after UINavigationController pushViewController

查看:27
本文介绍了iOS 9:在 UINavigationController pushViewController 之后不再在 viewWillAppear 中设置框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决从 iOS 9 开始出现的视图放置错误.我正在从 xib 文件(非自动布局)实例化视图控制器,然后将其推送到我的 UINavigationController.

I'm trying to solve a view placement bug that has arisen as of iOS 9. I am instantiating a view controller from a xib file (non-autolayout) and then pushing this onto my UINavigationController.

问题是当视图控制器的viewWillAppear方法被调用时,它的框架还没有调整到导航控制器的大小,仍然是在xib文件中设置的.现在直到 viewDidAppear 才正确设置.

The problem is that when the view controller's viewWillAppear method is called, its frame has not yet been adjusted to the navigation controller's size and is still what was set in the xib file. It doesn't get set properly now until viewDidAppear.

这完全搞砸了我的代码.有谁确切地知道导致这种情况发生的变化以及处理它的最佳方法是什么?我不想等到 viewDidAppear,因为这看起来很糟糕并且会导致糟糕的用户体验.

This is completely screwing up my code. Does anyone know precisely what has changed that is causing this and what is the best way to handle it? I don't want to wait until viewDidAppear because this will look bad and make for a poor user experience.

推荐答案

我也在寻找最好的解决方案.

I am also looking for the best fix.

我的临时方法是在viewDidLayoutSubviews"中调用viewDidAppear"中的代码.这样,一旦设置了框架,我的代码就会被调用.

My temporary one is to call the code that was in "viewDidAppear" in "viewDidLayoutSubviews". That way, my code will get called as soon as the frames are set.

但是,请确保添加一个布尔值或其他内容,这样您的代码就不会在每次调用 viewDidLayoutSubviews 时都被调用

But, make sure to add a boolean or something so that your code doesn't get called every time viewDidLayoutSubviews is called

-(void)viewDidLayoutSubviews{
   if (didLayoutSubviews == NO){
       didLayoutSubviews = YES;
       // perform code that was in viewWillAppear
   }
}

这篇关于iOS 9:在 UINavigationController pushViewController 之后不再在 viewWillAppear 中设置框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆