beginner iOS development, did not participate in business training courses, some do not know how to consult you.
when doing the effect of screen rotation, I used two view switching methods to deal with horizontal and vertical screens. The initial vertical screen can be displayed normally after switching to the horizontal screen, but there is a problem of view offset when it is transferred to the vertical screen.
I would like to ask, how did this problem arise? How do I fix it?
here is the code I implemented
- -(BOOL) shouldAutorotate {return YES;}
-
-(void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation duration: (NSTimeInterval) duration {
[super willRotateToInterfaceOrientation: (UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight) duration:0.5];
if (toInterfaceOrientation = = UIInterfaceOrientationPortrait) {self.view.bounds = CGRectMake(0, 0, 375, 667); self.view.frame = CGRectMake(0, 0, 375, 667); self.view = self->_portraitView;//_portraitView ...
}
else if (toInterfaceOrientation = = UIInterfaceOrientationLandscapeLeft) {self.view.bounds = CGRectMake(0, 0, 667, 375); self.view.frame = CGRectMake(0, 0, 667, 375); self.view = self->_landscapeView;//_landscapeView ...
}
else if (toInterfaceOrientation = = UIInterfaceOrientationLandscapeRight) {self.view.bounds = CGRectMake(0, 0, 667, 375); self.view.frame = CGRectMake(0, 0, 667, 375); self.view = self->_landscapeView; ...
}
}
the initial vertical screen of Beijing is all yellow. After the rotation, it looks like this.