我尝试了以下方法来强迫我的观点中的一个景观:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
- (BOOL)shouldAutorotate{
return YES;
}两种方法都不起作用。请注意,我是在模拟器和iPad上测试的。
谢谢
发布于 2013-10-01 19:11:41
以下是我是如何使用NavigationViewController强制我的一个视图成为景观的:
视图控制器中的https://stackoverflow.com/a/12662433/2394787
objc_msgSend(UIDevice currentDevice,@selector(setOrientation:),UIInterfaceOrientationLandscapeLeft);
希望这能帮助到别人。
发布于 2014-08-01 21:24:56
公认的答案似乎在iOS 7.1.2上不起作用。(它在模拟器上工作,但在设备上运行时不工作。)
不过,这似乎是可行的:
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];发布于 2014-08-09 08:05:41
int shouldShowInLandscape = 0;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(forceToLandscape:)
name:@"yourNameNotification"
object:nil];
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return UIInterfaceOrientationMaskLandscapeLeft;
} else {
if(shouldShowInLandscape)
{
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}
}
-(void) forceToLandscape:(NSNotification*) theNot
{
shouldShowInLandscape = [[theNot object] intValue];
}//来自UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"yourNameNotification"
object:[NSString stringWithFormat:@"1"]];
}
-(void) viewDidDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter]
postNotificationName:@"yourNameNotification"
object:[NSString stringWithFormat:@"0"]];
}//移除你的notificationCenter
https://stackoverflow.com/questions/19095161
复制相似问题