iOS 9 橫豎屏 切換 適配
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
[selfcreateBackBtn];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenRotate:animation:) name:@"UIWindowWillRotateNotification" object:nil];
}
-(void)dealloc{
[[NSNotificationCenterdefaultCenter] removeObserver:selfname:@"UIWindowWillRotateNotification"object:nil];
}
- (void)screenRotate:(NSNotification *)noti animation:(BOOL)animation
{
UIInterfaceOrientation orientation = [[noti.userInfoobjectForKey:@"UIWindowNewOrientationUserInfoKey"]
if (!noti) {
return;
}
animation = YES;
NSTimeInterval i = [UIApplicationsharedApplication].statusBarOrientationAnimationDuration;
NSTimeInterval time = 0.3 + i;
if (!animation) {
time = 0.0;
}
switch (orientation)
{
caseUIInterfaceOrientationPortrait:
{
if ([_ORIENTATIONisEqualToString:@"UIInterfaceOrientationPortrait"]) {
return;
}
DSLog(@"===========HOME鍵==正=============");
_ORIENTATION = @"UIInterfaceOrientationPortrait";
}
break;
caseUIInterfaceOrientationPortraitUpsideDown:
{
if ([_ORIENTATIONisEqualToString:@"UIInterfaceOrientationPortraitUpsideDown"]) {
return;
}
DSLog(@"==========HOME鍵===反=============");
_ORIENTATION = @"UIInterfaceOrientationPortraitUpsideDown";
}
break;
caseUIInterfaceOrientationLandscapeRight:
{
if ([_ORIENTATIONisEqualToString:@"UIInterfaceOrientationLandscapeRight"]) {
return;
}
DSLog(@"=========HOME鍵====右邊=============");
_ORIENTATION = @"UIInterfaceOrientationLandscapeRight";
// 這裡是給相應的view對應旋轉
// [UIView animateWithDuration:time animations:^{
// _userVc.view.transform = CGAffineTransformMakeRotation(M_PI_2);
// } completion:nil];
}
break;
caseUIInterfaceOrientationLandscapeLeft:
{
if ([_ORIENTATIONisEqualToString:@"UIInterfaceOrientationLandscapeLeft"]) {
return;
}
DSLog(@"==========HOME鍵===左邊=============");
_ORIENTATION = @"UIInterfaceOrientationLandscapeLeft";
// 這裡是給相應的的view對應旋轉
// [UIView animateWithDuration:time animations:^{
// _userVc.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
// } completion:nil];
}
break;
default:
break;
}
}