IT분야/iOS
[iOS] iPhone, iPad 가로, 세로 고정
suroMind
2012. 2. 5. 14:24
아이폰을 개발하다 보면 회전을 한다든지 세로 또는 가로 고정으로 해야 할 때가 있습니다.
아래 코드는 UIViewController 에서 모든 방향으로 회전이 가능한 코드입니다.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
return 값을 넘겨 줄때 해당 상황에 맞게 넘겨 주면 되겠지요
1. 세로 고정
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown);
}
2. 가로 고정
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft|| interfaceOrientation ==UIInterfaceOrientationLandscapeRight);
}