I'm not sure which UIDevice
method that you are saying has been removed, but the following has worked for me (this does use the UIDevice
orientation
method). Bottom line, if you have a view that only accepts landscape, you can use the following to force iOS to change the orientation. It's curious, but it works. I apologize that I can't give credit to the original author, but once came across this elsewhere on StackOverflow:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)forceLandscape
{
// make sure shouldAutorotateToInterfaceOrientation is configured to accept only landscape
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window addSubview:view];
}
}
The equivalent to force portrait mode (assuming, of course, your shouldAutorotateToInterfaceOrientation
accepts only portrait):
- (void)forcePortrait
{
// make sure shouldAutorotateToInterfaceOrientation is configured to accept only portrait
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window addSubview:view];
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…