2009-06-15 4 views
2

누구든지이 작업을 수행하는 방법을 알고 있습니까?장치 자동 회전 기능이없는 iPhone의 회전을 어떻게 감지합니까?

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

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

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
} 

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
} 

- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
} 

- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration { 
} 

는하지만 실제로 회전을 수행의 UIViewController 아니다 두려워 (모든 슈퍼 클래스를 호출 내의 UIViewController의 방법이 아닌 회전 무시) 회전에서 장치를 방지 할 수 있습니다

나는이 생각했다.

내 UIViewController는 UINavigationController에 있습니다.

누구든지 아이디어가 있습니까?

건배, 닉.

+1

실제로 모든 비어있는 대리자 메서드를 재정의 할 필요는 없으며 실제로 사용해야하는 메서드 만 재정의해야합니다. 호출자는 사용자가 정의했는지 여부에 관계없이 서브 클래스가 호출하기 전에 특정 메소드에 응답하는지 테스트해야합니다. 그것은 대표자가 일하는 방식 일뿐입니다. –

답변

20

당신은 (UIDevice.h에서) 알림 UIDeviceOrientationDidChangeNotification에 등록하고 방향 변경에 대해 신경 때이 메소드를 호출 할 수

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

더 이상이 방법, 방향 변경에 관심없는 전화 :

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 

해당하는 경우 알림이 전송되며 [UIDevice currentDevice].orientation을 확인하면 현재 방향이 무엇인지 확인할 수 있습니다.

+0

감사합니다 - 이것은 정확히 내가 한 것입니다! –

+0

나쁜 부작용은 장치가 더 이상 잠자기 상태가되지 않는다는 것입니다. – drvdijk

1

YESshouldAutorotateToInterfaceOrientation:에서 반환합니다. 귀하가 의도 한 것이 아닌 것으로 판단됩니다. 장치가 회전하지 않도록 구현해야하는 유일한 방법입니다.

장치의 현재 방향을 가져 오는 경우 [[UIDevice currentDevice] orientation]을 사용할 수 있습니다.

+0

안녕하세요 - 귀하의 제안에 감사드립니다! [[UIDevice currentDevice] orientation] 현재 방향을 가져옵니다. 그러나 전화가 자동으로 회전하지 않으면 이러한 상황이 발생하면이를 감지해야합니다. shouldAutorotateToInterfaceOrientation에서 NO를 반환하면 어떤 대리자 함수도 호출되지 않으므로 회전이 발생할 때 감지 기능이 느슨합니다. 다른 사람이 아이디어를 갖고 있습니까? 건배, Nick. –

4

참고 : shouldAutoRotateToInterfaceOrientation은 2.x에서 순환하기 위해 호출해야했지만 3.0에서는 훨씬 덜 일관성이 있습니다. 다른 게시물에 언급 된 알림은 신뢰할 수있는 로테이션 표시 방법입니다.

+0

팁 켄달 감사합니다! 엔 –

관련 문제