IOS学习之响应设备的横竖屏状态,旋转界面达到横竖屏效果

监听 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];
}

分享文章:IOS学习之响应设备的横竖屏状态,旋转界面达到横竖屏效果
URL链接:http://bzwzjz.com/article/pssjjo.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 定制网站建设多少钱 成都网站设计制作公司 成都网站建设 外贸网站设计方案 成都企业网站建设公司 成都网站建设 成都网站建设 企业网站设计 网站制作报价 营销网站建设 网站制作 成都网站建设公司 成都商城网站建设 成都网站制作 成都商城网站制作 重庆企业网站建设 成都网站设计 成都企业网站设计 网站制作 重庆企业网站建设 营销型网站建设 成都网站建设