简体   繁体   中英

Previous UIViewController bleeds through when presented modally on iOS7

When presenting a ViewController modally with a storyboard segue, the previous ViewController bleeds through.

UIViewController B presents UIViewController C modally. Both of them have UIScrollView (if that matters). When I get to ViewController C, it's almost as though the the entire view is just a tiny bit smaller so that the previous ViewController bleeds through. It looks something like this:

1个

The bottom light grey is part of the previous controller. The way I actually confirmed it was the previous view controller is I added this method to it:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   NSLog(@"I'm being touched!");
}

This only occurs in iOS 7 and not on iOS 8.

Well, turns out the reason this was occurring was because I had something similar to this in the appdelegate to get black status bars:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

    [application setStatusBarStyle:UIStatusBarStyleLightContent];
     [application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

    self.window.clipsToBounds =YES;            
    self.window.frame =CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}

This was an issue because it was changing the entire window size. It wasn't causing an issue in the first view, but fo some reason it was causing an issue during modal segue's. So to fix it I changed it to something similar to:

if (IS_IOS7) {
        UIView *addStatusBar = [[UIView alloc] init];
        addStatusBar.frame = CGRectMake(0, 0, 320, 20);
        addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //You can give your own color pattern
        [self.window.rootViewController.view addSubview:addStatusBar];
    }

This method seemed to work better because instead of changing the window size, I was simply adding a UIView that was black to the top of the frame. This kept the window size the same and no more bleeding through.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM