iOS6以降の回転設定
// 回転可否の指定
- (BOOL)shouldAutorotate {
return YES;
}
// 回転可能方向の指定
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000//ios8以下の場合
- (NSUInteger)supportedInterfaceOrientations
#else //ios9以降の場合
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
return UIInterfaceOrientationMaskAll;//全方向
}
// 初期画面方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait; //ポートレイト
}
// ios5回転可能方向の指定
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
return YES;//全方向
}
[[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(deviceDidRotate:) name:UIDeviceOrientationDidChangeNotificationobject:nil];
- (void)deviceDidRotate:(NSNotification*)note{
UIDeviceOrientation orientation = [note.object orientation];
switch(orientation){
caseUIDeviceOrientationPortrait: …以下省略
- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id)coordinator; {
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection{
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator {
[coordinator animateAlongsideTransition:^(id context) {
//回転前
} completion:^(id context){
//回転後
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
if(self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact){
//縦方向のサイズがCompactの場合
}else{
//縦方向のサイズがCompact以外の場合
}
UIInterfaceOrientation orientation = [[UIApplicationsharedApplication] statusBarOrientation];