2011-06-14 3 views
12

는/전화가 (상하 반전 또는) 초상화에있을 수 있습니다 어디 지금 문제가있다, 그러나iPhone에서 인터페이스 방향을 변경하는 방법이 있습니까? 내가 할 수있는 방법을 알고

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

를 사용하여 회전 방향을 허용하고 어떤 점에서 나는를 회전하려면 마치 사용자가 풍경으로 회전 한 것처럼 화면에 표시됩니다. 이 시점에서 필자는 자동 실행 기능이 더 이상 작동하지 않게하려고합니다. 인터페이스 방향이 가로 방향으로 유지되도록하고 싶습니다. 이것을 할 수있는 방법이 있습니까? 아마 자동 회전을 끄기위한 해킹을 알아낼 수는 있지만 처음부터 회전을 강요하는 것은 어떻게해야할지 모르겠다.

는 여기에 내가 할 노력하고있어 무엇 :

  • 응용가 어떠한 방향으로 회전합니다. 모든 것이 정상입니다.

  • 이벤트가 발생합니다.

  • 이제 자동 가로 방향 조정 기능은 조경 및 랜드 스케이프 전용으로 작동합니다. 또한 사용자가 세로 또는 세로 방향으로 이동하면 프로그램 방식으로 사용자가 해당 방향으로 사용자를 고정시키기 위해 landscaperight로 회전합니다.

그냥 사용자가 무슨 일이 일어나고 있는지 알려주하는 UIAlertView (내가 그렇게하는 방법을 알고) 강제 회전하기 전에 팝업 할 상황이 까다로 만들려면, 나는에 alertView 뒤에 화면하려는 회전하지만 alertView는 회전하지 않습니다. 이것은 가능한가?

감사합니다.

답변

-2

네, 그렇게 할 수 있습니다. 당신이해야 할 것은에 - 단순히 문제

+2

이 API는 숨겨져 있으며 UIDevice 인스턴스의 orientation 속성은 읽기 전용이므로 Apple에서 검토하는 동안 문제가 발생할 수 있습니다. –

+0

<방향을 변경하려는.>에 대해 UIInterfaceOrientation 유형을 id로 강제 변환 할 수 없습니다. 해결 방법은 무엇입니까? – schellsan

0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
     return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
    } 


    // orientation view swapping logic 
- (void)didRotate:(NSNotification *)notification { 


    UIDeviceOrientation newOrientation = [[UIDevice currentDevice] orientation]; 
    if (newOrientation != UIDeviceOrientationUnknown || newOrientation != UIDeviceOrientationFaceUp || newOrientation != UIDeviceOrientationFaceDown) 
    { 
      orientation = newOrientation; 

    } 

    // Write your orientation logic here 
     if ((orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)) 
    { 
    // Clear the current view and insert the orientation specific view. 
     [self clearCurrentView]; 
     [self.view insertSubview:yourLandscapeView atIndex:0]; 

    } else if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) 
    { 
      // Clear the current view and insert the orientation specific view. 
      [self clearCurrentView]; 
      [self.view insertSubview:yourPortraitView atIndex:0]; 

    } 
} 

를 해결하고 경우에 그 통지를 추가합니다

if (self.interfaceOrientation == <current orientation>) { 
     [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)<to which orientation you want to change.>]; 
    } 

다음과 같은 코드를 포함 (무효) viewwillappear 방법

0

당신은 할 수 없습니다 . 최소한 애플이 허용 할 방식은 아니다. 자동 회전은 전체 응용 프로그램에서 동일하도록 설계되었습니다. 뷰를 수동으로 회전시키는 코드를 만들 수 있지만, UIDevice에 관한 한 동일한 방향이됩니다.

1

상황에 가장 적합한 솔루션은 가로 방향으로 바꾸고 사용자가 방향을 바꿀 때까지 프로그램을 일시 중지하도록 사용자에게 알리는 것입니다. 그런 다음 사용자가 장치를 회전하면 대리자 메서드를 처리하고 가로 모드로 화면을 표시하기 시작할 수 있습니다. 이 접근 방식은 많은 앱 스토어 애플리케이션에서 처리되었으며 앱 스토어에서 승인 된 앱을 얻는 가장 좋은 방법 중 하나 인 것처럼 보입니다. 나는 그것이 의미가 있기를 바랍니다. 애플에 따르면

0

, 당신은 장치 방향 회전 API에서 제공하는 기본 동작을하지 않으려면 :

당신은 통제 걸릴 수

: 앱이 을 지원

  • 방향을
  • 두 방향 간의 회전이 화면에서 움직이는 방법.

내가이 글을 읽을 방법은 "당신은 이런 것들 중 하나를 제어 할 수 있습니다,하지만 아무것도 다른"이거나 "당신은이 두 가지를 제어 할 수 있습니다."

방향을 강제 변경하는 방법을 명시 적으로 설명한 설명서에는 아무것도 표시되지 않습니다. 이 모든 것은 장치에 의해 처리되므로 장치를 들고있는 사람이 더 자연스럽고 친근 해 보입니다. 말이 돼?

회전 변화에 여기 문서를 참조하십시오 :

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html

마지막으로, 나는 애플의 승인을 받아야하지 않을 것이라고 더 이렇게 할 수없는 말을하고있다. 나는 Praveen의 대답에 투표했습니다. 왜냐하면 당신이하려는 일에 대해 다른 접근 방식을 고려해야 할 필요가 있다고 생각하기 때문입니다.

관련 문제