美文网首页
iOS横竖屏开发(监听)

iOS横竖屏开发(监听)

作者: 布谷布谷7788 | 来源:发表于2017-11-30 17:47 被阅读0次

项目涉及横屏竖屏都要开发的时候,并要设计两个UI; 所以监听横竖屏的变化的是必须的

- (void)viewWillAppear:(BOOL)animated{

[super viewWillAppear:animated];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

}

- (void)dealloc{

[[NSNotificationCenter defaultCenter] removeObserver:self];

}

- (void)orientChange:(NSNotification *)notification{

CGFloat height = [UIScreen mainScreen].bounds.size.height;

CGFloat width = [UIScreen mainScreen].bounds.size.width;

CGFloat  index = 0 ;

UIDeviceOrientation  orient = [UIDevice currentDevice].orientation;

if (orient == UIDeviceOrientationPortrait) {

NSLog(@"竖屏");

//        index = width;

//        width = height;

//        height = index;

}else  if (orient == UIDeviceOrientationLandscapeLeft){

NSLog(@"横屏");

index = width;

width = height;

height = index;

}

[self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

}

相关文章

网友评论

      本文标题:iOS横竖屏开发(监听)

      本文链接:https://www.haomeiwen.com/subject/matbbxtx.html