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

查看:247
本文介绍了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天全站免登陆