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

后端 未结 16 831
暖寄归人
暖寄归人 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:52

    I've had the same problem and here is my solution. Just add this to your AdDelegate:

    - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
    {
        if (!willLeave)
            [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
        return YES;
    }
    
    - (void)bannerViewActionDidFinish:(ADBannerView *)banner
    {
        [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
    }
    

    It's very simple; when the ad appears I hide the status bar and when the ad disappears I show it again. I hope the answer helps some people.

    0 讨论(0)
  • 2020-12-24 07:53

    For me, my modal view controller was a MoviePlayer and when it would be presented, it seemed that the status bar would be redrawn. When the view was dismissed, this second status bar would somehow create a 20px offset at the bottom of my screen, just above the tabbar controller.

    To fix this, when the modal view controller was presented, I would hide the status bar. When the movie had finished playing and the modal view controller was going to be dismissed, I made the status bar visible.

    - (void) moviePlayerLoadStateChanged:(NSNotification*)notification 
    {
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    }
    
    
    - (void) moviePlayBackDidFinish:(NSNotification*)notification 
    {
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    }
    
    0 讨论(0)
  • 2020-12-24 07:54

    Turns out this was happening because I was calling my modalviewcontroller on the current view controller, but my view controller already had a another view controller loaded as a subview. Once I changed it to make the view controller in the subview, load the modal, then it went away. Thanks for all your help.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-24 07:58

    I had the same problem. My solution was to temporarily close the status bar just before switching views:

    - (void) temporarilyHideStatusBar {
      [[UIApplication sharedApplication] setStatusBarHidden:YES];
      [self performSelector:@selector(showStatusBar) withObject:nil afterDelay:0];
    }
    - (void) showStatusBar {
      [[UIApplication sharedApplication] setStatusBarHidden:NO];
    }
    
    // Use these by calling the hide function just before a broken view switch:
    [self temporarilyHideStatusBar];
    [self doViewSwitch];
    
    // No need to call [self showStatusBar]; explicitly.
    

    I experimented with other code-based solutions, and I like this one the best because it works 100% of the time - some of my frame-based solutions only worked most of the time - and because it has minimal user-visible effects.

    I suspect this is an Apple bug, and it would be nice to hear the official word from them on the best workaround.

    0 讨论(0)
  • 2020-12-24 07:58

    I used @Mark Hammonds answer, but simply reset the frame's offset to 0, ie:

    // this won't be called on the parent view if a modal dialog is dismissed. [self.parentViewController viewWillAppear: animated]; 
    // actually dismiss the modal dialog. 
    [[TOSplitViewController active] dismissModalViewControllerAnimated: animated]; 
    // fix the mysterious white bar that appeared on the top. 
    [[TOSplitViewController active].view setFrame:CGRectMake(0,0, [TOSplitViewController active].view.frame.size.width, [TOSplitViewController active].view.frame.size.height)];
    

    As you might guess, this was while trying to dismiss a modal dialog presented on top of a split view on an iPad application.

    I did try @Tyler's answer, and it didn't work for me.

    This on iOS4.1, targeting iPad 3.2.

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