iOS6 특정뷰 회전 처리
방금 해결한 문제.
특정뷰에서만 모든 방향으로 회전이 지원되게 하는 방법이다.
프로젝트는 이렇다
Xcode5.0
Device Orientation - Potrait
- Landscape Left
- Landscape Right
windows based 로 프로젝트 생성하여 AppDelegate에서 NavigationController 생성하여 루트뷰를 VODViewController 설정했다. setRootViewController로 하는것이 중요하다. addSubview로 했을시 회전 함수가 먹히지 않는다.
UIViewController *centerViewController = [[VODViewController alloc] initWithNibName:@"VODViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
[self.window setRootViewController:navigationController];
VODViewController 에서는 세로모드만 지원하게 하고 하위뷰인 VODDetatilView에서는 모든방향으로 회전이 가능하도록 한다. 붉은색으로 된 부분을 추가하자. 주석처리된 부분을 적용하면 frame이 깨져서 붉은색 부분으로 적용하였다.
# VODViewController.m
#import "VODViewController.h"
#import "VODDetailView.h"
@implementation UINavigationController (customRotation)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
/*
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
*/
@end
@interface VODViewController ()
@end
@implementation VODViewController
- (BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
@end
검색 키워드 : UINavigationcontroller rotation category
'IT > iOS' 카테고리의 다른 글
iOS 7 UI Difference between Simulator and real Device (0) | 2014.02.05 |
---|---|
navigation bar title color (0) | 2014.02.04 |
detailView 20pixel bug (0) | 2014.02.04 |
UITableView selected background color (0) | 2014.02.04 |
iPhone emoji encoding decoding (0) | 2014.01.28 |
CopyPNGfile error (0) | 2013.12.05 |
D-day 구하기 (0) | 2013.11.21 |
NSMutableArray Sort (0) | 2013.11.07 |