簡體   English   中英

iOS7 / IOS8在視圖控制器中僅允許縱向

[英]IOS7/IOS8 Allow only portrait in view controller

我正在為iPhone開發一個應用程序,該應用程序僅具有1個景觀視圖,因此我想為所有其他視圖阻止景觀,我已經嘗試過:

-(NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskPortrait;
}

但它仍然旋轉

我建議您將應用程序設置為縱向模式,然后在需要橫向模式時再允許橫向模式。

首先,按照先前的建議,單擊->項目名稱->常規->部署信息->僅選擇縱向作為設備方向。

其次,在您的AppDelegate.h添加此屬性。

@property (nonatomic) BOOL fullScreenVideoIsPlaying;

然后,在您的AppDelegate.m我將添加此功能。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    if (self.fullScreenVideoIsPlaying == YES) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

完成此操作后,您需要在景觀控制器中創建一個函數或僅將此代碼添加到viewWillAppear方法中,這取決於您要如何實現。

((AppDelegate *)[[UIApplication sharedApplication] delegate]).fullScreenVideoIsPlaying = YES;
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];

然后將其設置回縱向模式。

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.fullScreenVideoIsPlaying = NO;

[self supportedInterfaceOrientations];

[self shouldAutorotate:UIInterfaceOrientationPortrait];

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];

iOS 8可能需要這些功能。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)shouldAutorotate:(UIInterfaceOrientation)interfaceOrientation{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

希望對您有所幫助。:)

單擊項目,然后從中選擇方向設置。

暫無
暫無

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

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