溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

IOS學習之 響應設備的橫豎屏狀態,旋轉界面 達到橫豎屏效果

發布時間:2020-07-30 13:38:16 來源:網絡 閱讀:866 作者:lyy201109210 欄目:移動開發

監聽 UIDeviceOrientationDidChangeNotification的廣播,再根據[[UIDevice currentDevice] orientation]獲取到屏幕的方向。



-(void) viewDidLoad {
     // Request to turn on accelerometer and begin receiving accelerometer events
     [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
 
- (void)orientationChanged:(NSNotification *)notification {
     // 獲取當前屏幕方向interfaceOrientation
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (orientation == UIDeviceOrientationLandscapeLeft) {// 左橫屏
        [self allPlay];
    } else {// 其他的都是正豎屏
        [self normalPlay];
    }
}
 
-(void) viewDidDisappear {
     // Request to stop receiving accelerometer events and turn off accelerometer
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
- (void) allPlay {
    // 按鈕
    [self.allScreenPlayBtn setHidden:YES];
    [self.normalPlayBtn setHidden:NO];
    // 狀態欄
    isStatusBaeHidden = YES;
    [self prefersStatusBarHidden];    // 是否隱藏狀態欄
    // 導航欄
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    // view旋轉
    [UIView beginAnimations:@"rotate" context:nil];
    [UIView setAnimationDuration:0.6f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    self.cbPlayer.view.transform = CGAffineTransformRotate(self.view.transform, M_PI_2);
    self.normalPlayBtn.transform = CGAffineTransformRotate(self.normalPlayBtn.transform, M_PI_2);
    [UIView commitAnimations];
    
    CGSize size = [[UIScreen mainScreen] bounds].size;
    CGRect rect = CGRectMake(0, -20, size.width, size.height);
    [self.cbPlayer.view setFrame:rect];
}
- (void) normalPlay {
    // 按鈕
    [self.allScreenPlayBtn setHidden:NO];
    [self.normalPlayBtn setHidden:YES];
    // 狀態欄
    isStatusBaeHidden = NO;
    [self prefersStatusBarHidden];
    // 導航欄
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    // view旋轉
    [UIView beginAnimations:@"rotate" context:nil];
    [UIView setAnimationDuration:0.6f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    self.cbPlayer.view.transform = CGAffineTransformRotate(self.view.transform, 0);
    self.normalPlayBtn.transform = CGAffineTransformRotate(self.normalPlayBtn.transform, 0);
    [UIView commitAnimations];
    [self.cbPlayer.view setFrame:self.playView.frame];
}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女