내 앱 디자인을 위해서는 회전 인식이 필요한 UIView가 필요합니다.IPad 순환 : 첫 번째 순환 이벤트가 통지되지 않습니까?
내 앱이 실행되면 UIApplicationWillChangeStatusBarOrientationNotification
을받습니다.
그러나 첫 번째 회전 (두 방향 중 하나의 방향)에서는 알림이 수신되지 않습니다.
이후의 모든 순환 이벤트는 예상 된 UIApplicationWillChangeStatusBarOrientationNotification
알림을 생성합니다.
기기 방향 확인을 위해 아래 코드를 변경하면 결과가 동일하므로 UIDeviceOrientationDidChangeNotification
알림에도 동일하게 적용됩니다.
코드 : (myUIView 초기화)
// set up to listen for rotation
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
(회전에 myUIView)
-(void)didRotate
{
if ([self landscape]) // rotated TO landscape
{
// do landscape stuff
}
}
(myUIView에서 회전 검사)
// answer the question: are we landscape? Yes or no. No indicates portrait.
-(BOOL)landscape
{
UIInterfaceOrientation iOrientation = [UIApplication sharedApplication].statusBarOrientation;
// Just get a displayable string version
NSString* iOrientationString ;
switch (iOrientation) {
case UIInterfaceOrientationPortrait : iOrientationString = @"UIInterfaceOrientationPortrait" ; break ;
case UIInterfaceOrientationPortraitUpsideDown : iOrientationString = @"UIInterfaceOrientationPortraitUpsideDown" ; break ;
case UIInterfaceOrientationLandscapeLeft:iOrientationString = @"UIInterfaceOrientationLandscapeLeft" ; break ;
case UIInterfaceOrientationLandscapeRight:iOrientationString = @"UIInterfaceOrientationLandscapeRight " ; break ;
}
NSLog(@"%@=%@" , @S(iOrientation) , iOrientationString) ;
return UIInterfaceOrientationIsLandscape(iOrientation);
}
내가 UIViewController
에 있습니다, -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
은 첫 번째 회전과 모두 호출됩니다. .
하지만 회전 인식보기를 원합니다. 첫 번째 이벤트가 누락되었다는 설명이나 해결 방법이 있습니까?
put [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; applicationdidFinishLaunchingWithOptions에 넣거나 awakefromnib에 넣습니다. – Maruti
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; applicationdidFinishLaunchingWithOptions 또는 awakefromnib에있는 위치는 (내 게시 된 코드의 첫 번째 행입니다.) 큰 차이를 만들 것입니까? 일종의) 일을 상기하십시오. 첫 번째 이벤트가 누락되었습니다. –