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

前端 未结 4 1238
我寻月下人不归
我寻月下人不归 2020-12-15 07:32

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

相关标签:
4条回答
  • 2020-12-15 07:38

    Try moving the layout code from viewWillAppear to viewWillLayoutSubviews.

    0 讨论(0)
  • 2020-12-15 07:51

    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
       }
    }
    
    0 讨论(0)
  • 2020-12-15 07:51

    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()
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-15 08:03

    I occurred this issue too,

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

    0 讨论(0)
提交回复
热议问题