亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在iOS 6中強制UIViewController面向肖像

如何在iOS 6中強制UIViewController面向肖像

iOS
米琪卡哇伊 2019-06-25 17:17:07
如何在iOS 6中強制UIViewController面向肖像就像ShouldAutorotateToInterfaceOrientation在IOS 6中被廢棄,我使用它強制使用特定的視圖只限于肖像畫在iOS 6中,正確的方法是什么?這只適用于我的應用程序中的一個區域,所有其他視圖都可以旋轉。
查看完整描述

3 回答

?
ABOUTYOU

TA貢獻1812條經驗 獲得超5個贊

如果您希望我們所有的導航控制器都尊重頂部視圖控制器,您可以使用一個類別,這樣您就不需要查看并更改一堆類名。

@implementation UINavigationController (Rotation_IOS6)-(BOOL)shouldAutorotate{
    return [[self.viewControllers lastObject] shouldAutorotate];}-(NSUInteger)supportedInterfaceOrientations{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];}@end

正如一些評論所指出的,這是一個快速解決問題的方法。一個更好的解決方案是子類UINavigationController,并將這些方法放在那里。子類還有助于支持6和7。



查看完整回答
反對 回復 2019-06-25
?
瀟瀟雨雨

TA貢獻1833條經驗 獲得超4個贊

這一答復涉及“任擇議定書”的評論中提出的問題:

為了迫使某一視圖出現在給定的位置上,請將以下內容顯示在威拉帕馬爾的視圖中:

UIApplication* application = [UIApplication sharedApplication];if (application.statusBarOrientation != UIInterfaceOrientationPortrait){
    UIViewController *c = [[UIViewController alloc]init];
    [self presentModalViewController:c animated:NO];
    [self dismissModalViewControllerAnimated:NO];}

有點像黑客,但這會迫使UIViewController即使以前的控制器是景觀,也要以肖像的形式呈現

iOS 7的最新情況

現在已不再推薦上述方法,因此對于IOS 7,請使用以下方法:

UIApplication* application = [UIApplication sharedApplication];if (application.statusBarOrientation != UIInterfaceOrientationPortrait){
     UIViewController *c = [[UIViewController alloc]init];
     [c.view setBackgroundColor:[UIColor redColor]];
     [self.navigationController presentViewController:c animated:NO completion:^{
            [self.navigationController dismissViewControllerAnimated:YES completion:^{
            }];
     }];}

有趣的是,在撰寫本報告時,任一現在或解散必須充滿活力。如果兩者都不是,那么你將得到一個白色的屏幕。不知道為什么這能讓它工作,但它確實!視動畫效果而定,視覺效果是不同的。


查看完整回答
反對 回復 2019-06-25
  • 3 回答
  • 0 關注
  • 525 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號