网络请求自动布局iOS知识收录

判断屏幕横屏/竖屏

2015-08-16  本文已影响6221人  YotrolZ

方法一:

- (void)viewWillLayoutSubviews

{

     [self _shouldRotateToOrientation:(UIDeviceOrientation)[UIApplication sharedApplication].statusBarOrientation];

}

-(void)_shouldRotateToOrientation:(UIDeviceOrientation)orientation {
   if (orientation == UIDeviceOrientationPortrait ||orientation ==
                UIDeviceOrientationPortraitUpsideDown) { // 竖屏
          
    } else { // 横屏
         
}

方法二:

#pragma mark - 屏幕翻转就会调用
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {

    // 记录当前是横屏还是竖屏
    BOOL isLandscape = size.width == kLandscapeWidth;
    
    // 翻转的时间
    CGFloat duration = [coordinator transitionDuration];
    
    [UIView animateWithDuration:duration animations:^{
       
        // 1.设置dockview的frame
        [self.dockView rotateToLandscape:isLandscape];
        
        // 2.屏幕翻转后(设置完dockview的frame)要重新设置contentView的x值
        self.contentView.x = self.dockView.width;
        
    }];
}
上一篇 下一篇

猜你喜欢

热点阅读