IPhone - After dismissing Modal View Controller - gap is left at top of page

后端 未结 16 968
暖寄归人
暖寄归人 2020-12-24 07:07

When starting the app, if the user doesn\'t have login information stored, I want to display a modal view controller to force the entry of this information. I found through

16条回答
  •  执笔经年
    2020-12-24 07:56

    I find that both presenting and dismissing modal view controllers cause this, especially when you want to do custom layouting in -viewDidLoad (which some say you shouldn't, but I've never found a better, working way). What I do is:

    [self.view addSubview:self.viewController1.view]; // I suppose this layouts all (sub)views.
    [self.viewController1.view removeFromSuperview]; 
    

    Now you can present as such:

        self.viewController1.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self.viewController2 presentModalViewController:self.viewController1 animated:YES];
    

    without risking viewController1 to be laid out in a foul way until transition done, then snapping to wherever it should be. The same applies to dismissing. Works for me on iOS 3.0 though 5.0, iPhone and iPad.

提交回复
热议问题