Locking Interface Orientation?

2019-08-16 07:35发布

问题:

On the initial view of my app I want the interface to be portrait only but on the view controllers after that it can be any orientation. I tried this code to lock it but it doesn't work and the view can still rotate:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }

回答1:

The reason that code is not working is most likely because you are running iOS 6. Try this code instead:

- (BOOL)shouldAutorotate {
    return NO;
}