[iPhone] - 시작하세요! 아이폰 3 프로그래밍 - Part 5. 자동회전과 자동크기조절

iPhone/[위키북스]시작하세요! 아이폰3 프로그래밍 2010. 7. 12. 22:05

* 세로보기 모드 (portrait - 길고 얇은) / 가로보기 모드 (landscape - 짧고 옆으로 넓은)

* 세로보기 모드에서 뷰는 너비 320 px / 높이 460 px (상태 표시줄이 없다면 높이는 480 px)

* 가로보기 모드에서 너비는 480 px / 높이 300 px (상태 표시줄이 없다면 높이는 320 px)

* 애플리케이션에서 회전 기능을 관리하는 3가지 기능

-- autoSize속성으로 회전 처리 하기
-- 회전할때 뷰 재구성하기
-- 뷰 전환하기 (세로보기모드 / 가로보기모드)

* autoSize속성으로 회전 처리 하기
-(BOOL)shouldAutorotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
return 값에 지원하고자 하는 방향만 return YES를 설정해주면된다.

-- 4가지 방식으로 응답
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationPortraitUpSideDown
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight


* 회전할 때 뷰 재구성하기
- willAnimateRorotationToInterfaceOrientation:duration: 메서드를 사용하면된다. 이메서드는 회전이 일어나면, 마지막 애니메이션 동작 전에 자동으로 호출된다.

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
 if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
 {
  button1.frame = CGRectMake(20, 20, 125, 125);
  button2.frame = CGRectMake(175, 20, 125, 125);
  button3.frame = CGRectMake(20, 168, 125, 125);
  button4.frame = CGRectMake(175, 168, 125, 125);
  button5.frame = CGRectMake(20, 315, 125, 125);
  button6.frame = CGRectMake(175, 315, 125, 125);
 } else {
  button1.frame = CGRectMake(20, 20, 125, 125);
  button2.frame = CGRectMake(20, 155, 125, 125);
  button3.frame = CGRectMake(177, 20, 125, 125);
  button4.frame = CGRectMake(177, 155, 125, 125);
  button5.frame = CGRectMake(328, 20, 125, 125);
  button6.frame = CGRectMake(328, 155, 125, 125);
 }
}

- 버튼과 같은 컨트롤들을 포함해서, 모든 뷰의 크기와 위치가 CGRect타입의 구조체인 frame이라는 속성에 명시되어 있다. CGRectMake는 CGRect를 쉽게 만들기 위해서 애플이 제공하는 함수로서, 너비와 높이와 함께 x,y위치를 명시하기만 하면된다.

* 뷰 전환하기
- 템플릿을 통해 제공되는 뷰는 크기를 조절 할수 없다.

---------------------------------------------------------------
P113 작업중  자꾸 아래와 같은 메세지가 console에 출력되었다.
당연히 Simulator에서도 작동하지 않았고.. 그래서 다음 이미지와 같이 해결하였다.


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SwapViewController" nib but the view outlet was not set.'

1. 새롭게 추가된 view중 portrait에 UIView portrait도 연결하였지만 기본 view도 같이 연결해 주었다.
: