簡體   English   中英

在橫向模式下鎖定特定的UIViewController +強制橫向

[英]Lock a specific UIViewController in Landscape mode + Force landscape orientation

我有一個特定的UIViewController,我只想將其鎖定/強制為“橫向”。

這是我到目前為止所做的,但沒有成功。...我試圖使此功能適用於iOS 6和7。

我究竟做錯了什么?

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{

// Return YES for supported orientations
return UIInterfaceOrientationMaskLandscape;

 }

- (BOOL)shouldAutorotate {

 return YES;

 }

- (NSUInteger)supportedInterfaceOrientations{
if([AppConst isIPad]){
    return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskLandscape;
}

//not ios6

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([AppConst isIPad]){
    return YES;
}
return interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}

在iOS 6中不應該使用方法應該AutorotateToInterfaceOrientation。您想改用方法supportedInterfaceOrientations。 如果您還想在iOS 5或更早版本上運行,則需要實現這兩種方法。

您還應該實現方法shouldAutorotate。

只需刪除視圖控制器中的所有這些方法並使用此方法

-(void)viewDidAppear:(BOOL)animated{

[[UIDevice currentDevice] setValue:
 [NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft]
                            forKey:@"orientation"];} 

快樂編碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM