2016-10-24 2 views
1

iOS에서 새로운 기능이며 회전 관련 문제가 있습니다. 단일 뷰 컨트롤러 회전을 세로 방향으로 고정하면됩니다. 이 코드를 사용하고 있습니다.대물 렌즈 C에서 세로의 회전 방향을 고정하는 방법

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:NO]; 
    [UIView setAnimationsEnabled:NO]; 
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]; 
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 
} 

가로로는 잘되지만 세로로는 작동하지 않습니다. 어떻게 초상화로 사용할 수 있습니까? 이런 초상화 기법을 시도했습니다.

  1. UIInterfaceOrientationMaskPortrait
  2. UIInterfaceOrientationPortrait
  3. UIInterfaceOrientationPortraitUpsideDown
  4. UIInterfaceOrientationMaskPortraitUpsideDown 그러나 나를 위해 전혀 작동합니다. 미리 감사드립니다.
+0

이 시도 세로로

가 // 잠금 방향 http://stackoverflow.com/questions/26357162/how- to-force-view-controller-orientation-in-ios-8 –

+0

@UmairAfzal 이는 내가 사용했던 것과 동일합니다. – Muju

+0

iOS 버전이 무엇입니까? –

답변

0

이 코드는 IOS 9 이상에서 테스트 한 세로 방향보기 컨트롤러로 사용하십시오.

-(UIInterfaceOrientationMask)supportedInterfaceOrientations { 
return UIInterfaceOrientationMaskPortrait; 
} 

-(NSUInteger)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController { 
    return UIInterfaceOrientationMaskPortrait; 
} 

또는

-(NSUInteger)supportedInterfaceOrientations{ 
return UIInterfaceOrientationMaskPortrait; 
} 

-(BOOL)shouldAutorotate { 
return NO; 
} 

확인이 (iOS 6 shouldAutorotate: is NOT being called) 대답

+0

이 메서드를 호출하는 위치 및 방법은 무엇입니까? – Muju

+0

'Support Orientition'구현에서 경고 충돌 반환 유형을 보여줍니다. 첫 번째 코드에서. – Muju

+0

@Muju 편집을 확인하십시오. –