你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> Orientation

Orientation

編輯:IOS開發綜合

上面用在旋轉視圖控制器的幾個辦法,十分好用,其實還有少量的其他判別辦法,都不太靠譜


#import "OrientationViewController.h"

@interface OrientationViewController ()

@property (nonatomic, assign) BOOL shouldRotate;

@end

@implementation OrientationViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    /* IOS7 視圖進入的時分判別方向 */
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8)
    {
        switch ([UIDevice currentDevice].orientation)
        {
            case UIDeviceOrientationPortrait:
            {
                NSLog(@"Portrait !!!");
                break;
            }
            case UIDeviceOrientationLandscapeLeft:
            case UIDeviceOrientationLandscapeRight:
            {
                NSLog(@"Landspace !!!");
                break;
            }
            default:
                NSLog(@"Unkown !!!");
                break;
        }
    }
}

- (void)configureNotificaiton
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:)
                                                 name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}

- (void)statusBarOrientationChange:(NSNotification *)notification
{
    /* 配合這個辦法,用在更新界面,控制先後 */
}


#pragma mark - UIViewController (UIViewControllerRotation).

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8)
    {
        switch ([UIDevice currentDevice].orientation)
        {
            case UIDeviceOrientationPortrait:
            {
                NSLog(@"Portrait !!!");
                break;
            }
                
            case UIDeviceOrientationLandscapeLeft:
            case UIDeviceOrientationLandscapeRight:
            {
                NSLog(@"Landspace !!!");
                break;
            }
            default:
                NSLog(@"Unkown !!!");
                break;
        }
    }
    else
    {
        /* IOS8 以上的處置 */
    }
}


#pragma mark - Orientation Handler.

- (BOOL)shouldAutorotate
{
    if (self.shouldRotate)
        return YES;
    else
        return NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if (self.shouldRotate)
        return YES;
    else
        return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if (!self.shouldRotate)
    {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
    }
    return UIInterfaceOrientationMaskAll;
}

@end


【Orientation】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved