iOS横竖屏开发(监听)
项目涉及横屏竖屏都要开发的时候,并要设计两个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)];
}