iOS 9: Frame no longer set in viewWillAppear after UINavigationController pushViewController

谁说我不能喝 提交于 2019-11-28 23:21:30

I am also looking for the best fix.

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.

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

I occurred this issue too,

try to uncheck option "Resize View From NIB" from storyboard

Try moving the layout code from viewWillAppear to viewWillLayoutSubviews.

A little bit updated NickProvost's answer:

private var loadViewToken: dispatch_once_t = 0

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    dispatch_once(&loadViewToken) { [weak self] in
        if let wSelf = self {
            wSelf.setupView()
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!