0

I am adding a view Controller to an existing one using addChildViewController and addSubview. The problem is that when the device is rotating the back view controller is briefly visible. I am using notifications to detect a rotation and replace the presented view controller (landscape and portrait are on different scenes in the storyboard)

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

    if(portrait){
        self.landscapeViewiPad.hidden = YES;
        self.portraitViewiPad.hidden = NO;
    }else{
        self.landscapeViewiPad.hidden = NO;
        self.portraitViewiPad.hidden = YES;
    }
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];

    [UIView commitAnimations];
}

I notice that this problem is only on iOs8. Does anybody have an idea about what could be done to fix this.

brandonscript
  • 68,675
  • 32
  • 163
  • 220
user1028028
  • 6,323
  • 9
  • 34
  • 59
  • I know, this happens to me too.. So, annoying lol.. But, I think you can freeze or delay the UI.. – valbu17 Nov 14 '14 at 05:49
  • I think it's going to be tough to get that working in iOS 8. The first problem is using notifications to rotate your view (see http://stackoverflow.com/questions/26669799/device-tilting-up-down-and-sideways-triggers-orientation-notification/26717691#26717691). Also, swapping portrait/landscape views isn't the "right" way to do things anymore, so I'm not surprised it's glitchy. Apple is pushing autolayout, so these manual methods are becoming increasingly dicey. Might be time to re-design... ugh. – Anna Dickinson Nov 15 '14 at 00:29

1 Answers1

0

If it's only about a UI issue you might just postpone the hiding of the original view a bit:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_USEC), dispatch_get_main_queue(),
               ^{
                   self.landscapeViewiPad.hidden = NO;
               });

NSEC_PER_USEC is 1/1000s, that might be too short and you might need to try yourself what works for you.

If you reply "this is a hack" I would agree :)

dogsgod
  • 6,267
  • 6
  • 25
  • 53
  • The problem a UIView animate method ... in iOs 8 I need to set the duration to 0 instead of 0.5 and everything is ok – user1028028 Nov 14 '14 at 12:37