2011-09-06 5 views
0

nib 파일 someNib.xib에 있다고 가정 해 보겠습니다.beginGeneratingDeviceOrientationNotifications에 의해 생성 된 메소드 호출 중지

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationChanged) 
               name:UIDeviceOrientationDidChangeNotification object:nil]; 

무엇을이 라인이하는 것은이 장치가 회전하는 deviceOrientationChanged 방법의 초과 근무를 호출하는 것입니다 : 장치 방향이 후 변경 한 경우 나에게 말할 수 있기 위해서는 내가보기 안쪽이 부하 방법을했다 놓습니다. 내 deviceOrientationChanged 메소드는 다음과 같습니다.

-(void) deviceOrientationChanged{ 

    if(self.view.frame.size.width<800) 
    { 
     //means device is on portrait mode 
    } else { 

     //means device is on landscape mode 
    } 


} 

이렇게 모든 것이이 nib 파일과 잘 맞습니다. 문제는 다음과 같이 다른 nib 파일을로드 할 때 발생합니다.

  // release allocated variables 
      // VCHome is the name of the nib file 
      VCHome *control = [VCHome alloc]; 
      [control initWithNibName:@"VCHome" bundle:nil]; 
      UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:control]; 
      [self presentModalViewController:navControl animated:YES]; 
      [navControl setNavigationBarHidden:YES]; 
      [control release]; 
      [navControl release]; 

이 시점까지 모든 것이 잘 작동합니다. 나는 이제 새로운 펜촉 파일에 있으며 VCHome과 상호 작용할 수 있습니다.

VCHome nib 파일을 사용할 때 장치를 회전시킬 때 deviceOrientationChanged 메서드가 호출되는 이유는 무엇입니까? VCHome nib 파일을로드했을 때 someNib ​​(마지막 펜촉)을 릴리스해야이 메서드가 호출되지 않습니다. someNib을 더 이상 사용할 계획이 없으며 someNib을로드 한 적이없는 것처럼 VCHome 펜촉을 사용하고 싶습니다.

답변

3

의 UIViewController는 여러 가지 방법으로 당신이 당신을 위해 방향 변경의 수명주기를 처리 구현할 수 있습니다

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

당신이 그것을 대신이 방법을 사용하는 것이 가장 간단한 UIViewControllers를 사용하는 경우 이벤트 등록. 당신은 장치의 방향을 가로 또는 세로가 있는지 확인해야하는 경우

또한, 그것의 더 나은 사용하기 :

UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 
if (UIInterfaceOrientationIsLandscape(currentOrientation)) 
{ 
    ... 
} 
관련 문제