中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

IOS UIDevice & IOS檢測屏幕旋轉(zhuǎn)實(shí)例

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用

UIDevice類提供了一個(gè)單例實(shí)例代表當(dāng)前的設(shè)備。從這個(gè)實(shí)例中可以獲得的信息設(shè)備,比如操作系統(tǒng)名稱、電池電量值(batteryLevel)、電池狀態(tài)(batteryState)、設(shè)備的類型(model,比如iPod、iPhone等)、設(shè)備的系統(tǒng)(systemVersion)
屏幕的旋轉(zhuǎn)朝向可以通過  [[UIDevice currentDevice]orientation] 判斷,orientation是個(gè)Integer類型,每個(gè)值表示相應(yīng)的朝向,必須在調(diào)用beginGeneratingDeviceOrientationNotifications方法后,此orientation屬性才有效,否則一直是0。

//
//  ViewController.m
//
 
#import "ViewController.h"
 
@interface ViewController ()
/**
 *  UIImageView
 */
@property(nonatomic,strong)UIImageView *imageView;
 
 
@end
 
 
@implementation ViewController
 
 
- (void)handleDeviceOrientationDidChange:(UIInterfaceOrientation)interfaceOrientation
{
    //1.獲取 當(dāng)前設(shè)備 實(shí)例
    UIDevice *device = [UIDevice currentDevice] ;
     
     
     
     
    /**
     *  2.取得當(dāng)前Device的方向,Device的方向類型為Integer
     *
     *  必須調(diào)用beginGeneratingDeviceOrientationNotifications方法后,此orientation屬性才有效,否則一直是0。orientation用于判斷設(shè)備的朝向,與應(yīng)用UI方向無關(guān)
     *
     *  @param device.orientation
     *
     */
 
    switch (device.orientation) {
        case UIDeviceOrientationFaceUp:
            NSLog(@"屏幕朝上平躺");
            break;
             
        case UIDeviceOrientationFaceDown:
            NSLog(@"屏幕朝下平躺");
            break;
             
            //系統(tǒng)無法判斷目前Device的方向,有可能是斜置
        case UIDeviceOrientationUnknown:
            NSLog(@"未知方向");
            break;
             
        case UIDeviceOrientationLandscapeLeft:
            NSLog(@"屏幕向左橫置");
            break;
             
        case UIDeviceOrientationLandscapeRight:
            NSLog(@"屏幕向右橫置");
            break;
             
        case UIDeviceOrientationPortrait:
            NSLog(@"屏幕直立");
            break;
             
        case UIDeviceOrientationPortraitUpsideDown:
            NSLog(@"屏幕直立,上下顛倒");
            break;
             
        default:
            NSLog(@"無法辨識(shí)");
            break;
    }
 
}
 
 
- (void)viewDidLoad {
 
     
    //設(shè)備名稱  e.g. "My iPhone"
    NSString *strName = [[UIDevice currentDevice] name];
    NSLog(@"設(shè)備名稱:%@", strName);
 
     
     
    /**
     * 系統(tǒng)名稱 e.g. @"iOS"
     */
    NSString *strSysName = [[UIDevice currentDevice] systemName];
    NSLog(@"系統(tǒng)名稱:%@", strSysName);
     
     
 
    /**
     * 系統(tǒng)版本號(hào) e.g. @"4.0"
     */
    NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];
    NSLog(@"系統(tǒng)版本號(hào):%@", strSysVersion);
     
     
     
     
    /**
     * 設(shè)備類型 e.g. @"iPhone", @"iPod touch"
     */
    NSString *strModel = [[UIDevice currentDevice] model];
    NSLog(@"設(shè)備類型:%@", strModel);
     
     
     
    /**
     * 本地設(shè)備模式 localized version of model
     */
    NSString *strLocModel = [[UIDevice currentDevice] localizedModel];
    NSLog(@"本地設(shè)備模式:%@", strLocModel);
     
 
     
     
    /**
     * UUID  可用于唯一地標(biāo)識(shí)該設(shè)備
     */
    NSUUID *identifierForVendor = [[UIDevice currentDevice] identifierForVendor];
    NSLog(@"UUID:%@", identifierForVendor.UUIDString);
     
     
     
    /**
     * UIImage 對象
     */
    UIImage *image = [UIImage imageNamed:@"scroll.jpg"];
    self.imageView.image = image;
     
    // 設(shè)置圖片范圍
    CGFloat imageH = image.size.height;
    CGFloat imageW = image.size.width;
    CGFloat imageX = 0;
    CGFloat imageY = 0;
    self.imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
    [self.view addSubview:self.imageView];
     
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
 
 
-(void)viewDidAppear:(BOOL)animated
{
     
    /**
     *  開始生成 設(shè)備旋轉(zhuǎn) 通知
     */
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
     
     
    /**
     *  添加 設(shè)備旋轉(zhuǎn) 通知
     *
     *  @param handleDeviceOrientationDidChange: handleDeviceOrientationDidChange: description
     *
     *  @return return value description
     */
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleDeviceOrientationDidChange:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil
     ];
     
 
 
}
 
 
 
-(void)viewDidDisappear:(BOOL)animated
{
     
     
     
    /**
     *  銷毀 設(shè)備旋轉(zhuǎn) 通知
     *
     *  @return return value description
     */
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIDeviceOrientationDidChangeNotification
                                                  object:nil
     ];
     
     
    /**
     *  結(jié)束 設(shè)備旋轉(zhuǎn)通知
     *
     *  @return return value description
     */
    [[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];
     
}
 
 
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
 
 
 
#pragma 懶加載
 
- (UIImageView *)imageView
{
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
    }
    return _imageView;
}
 
@end

標(biāo)簽: idc isp

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:一個(gè)簡單的java死鎖示例

下一篇: iOS實(shí)現(xiàn)文件的寫操作