1

감사 작동하지 않습니다 변경 ... 그것을위한 내가방향 방향 내 장치에서 변경할 때 탐지 할</p> <p>사전에

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

와 방향이 방법 변경이 리스너를 사용

입니다
- (void) orientationChanged:(id)obj 
{ 
    if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     self.view=self.landscapeView; 
     NSLog(@"landscapeView"); 

     //[self loadView1]; 
    } 
    else 
    { 
     self.view = self.portraitView; 
     NSLog(@"portraitView"); 

     //[self loadView1]; 
    }  
} 

그리고 그 방향으로 ViewDidLoad() 메소드가있을 때마다 ...

하나가 나를 도울 수

..

+1

- (무효) willAnimateRotationToInterfaceOrientation : (UIInterfaceOrientation) toInterfaceOrientation 시간 : (NSTimeInterval)의 기간은 장치 방향 변경 – Narayana

답변

1
Try this 
[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) 
{ 
    //code here  
} 
+0

thats 내가 찾고있는 것이 있습니다. –

1

변경 다음

- (void) orientationChanged:(id)obj 
{ 

    if([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight) 
    { 
    self.view=self.landscapeView; 
    NSLog(@"landscapeView"); 

    //[self loadView1]; 
    } 
    else 
    { 
    self.view = self.portraitView; 
    NSLog(@"portraitView"); 

    //[self loadView1]; 
    }  
} 
0

왜 당신은 shouldAutorotateToInterfaceOrientation를 사용하지 않는? 이미 호출 된 UIViewController의 메소드입니다 ...

+0

내가에 따라 다른보기를 호출 할 때 호출 방향이 바뀌 었습니다 ... –

6

귀하의 질문은 막연합니다. 이것은 일반적인 설명입니다. 아래 방향을 언급 한 방법

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // return YES to supported orientation. 
} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
/* Subclasses may override this method to perform additional actions immediately 
    prior to the rotation. For example, you might use this method to disable view 
    interactions, stop media playback, or temporarily turn off expensive drawing or live 
    updates. You might also use it to swap the current view for one that reflects the new 
    interface orientation. When this method is called, the interfaceOrientation property 
    still contains the view’s original orientation. 
*/ 

} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    /*Subclasses may override this method to perform additional actions immediately after 
     the rotation. For example, you might use this method to reenable view interactions, 
     start media playback again, or turn on expensive drawing or live updates. By the time 
     this method is called, the interfaceOrientation property is already set to the new 
     orientation.*/ 
} 


- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration 
{ 
    /*This method is called from within the animation block used to rotate the view. 
     You can override this method and use it to configure additional animations that should 
     occur during the view rotation. For example, you could use it to adjust the zoom level 
     of your content, change the scroller position, or modify other animatable properties 
     of your view.*/ 
} 

if([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft) 
OR if(UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation)) 

같이있는 viewDidLoad 또는 viewDidAppear에서 장치의 방향을 확인하지 않기 때문에 많은 시간을 아래로 타는 동안

변경 처리하는 방법을 언급 대체 할 수 있습니다 아이폰/아이 패드가 탁자 위에 놓여진 것처럼 (나는 이것을 경험했다. 매우 불쾌한 이슈), 기대하지 않은 결과를 줄 것이다.

apple developer link은 처리 방향

에 대해 더 많은 정보를 줄 것이다
+0

이 링크는 매우 도움이됩니다. –

+0

감사합니다. 내 대답이 당신에게 유용하다는 것이 기쁩니다. 정답으로 표시하십시오.) – Krrish