0

가능한 중복에 무엇 확인 도움이 필요하십니까 :
iPhone orientation은 오리엔테이션 아이 패드가

은 아이 패드에서 어떤 방향에 따라, 나는 테이블 뷰의 배경을 설정하거나 제거하거나 필요 그것은 popover와 함께 작동하지 않기 때문입니다.

if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft){ 
    self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
    self.tableView.backgroundColor = [UIColor clearColor]; 
    NSLog(@"test"); 

어쩌면 더 나은 방법이있다 :

나는이 있지만 행운을 시도? 테이블이 마스터인지 팝 오버인지 확인하려면 배경을 설정 하시겠습니까?

답변

4

은 당신이 원하는 것을 달성하기 위해 여러 가지 방법이 있습니다 더 많거나 적은 :

  1. UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
  2. 더 해킹 틱 방법은 상태 표시 줄의 폭을 확인하는 것입니다.

당신이 옵션을 1로 갈 경우, 다음과 같이 방향을 확인할 수 있습니다

switch (orientation) { 
    case UIInterfaceOrientationPortrait: 
     // Do something. 
     break; 
    case UIInterfaceOrientationPortraitUpsideDown: 
     // Do something. 
     break; 
    case UIInterfaceOrientationLandscapeLeft: 
     // Do something. 
     break; 
    case UIInterfaceOrientationLandscapeRight: 
     // Do something. 
     break; 
} 

편집 : 자동으로 회전하도록 응용 프로그램을 얻으려면, 당신은이 작업을 수행 할 수 있습니다

- (BOOL)willAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    if ((interfaceOrientation == UIDeviceOrientationLandscapeRight)) NSLog(@"Right"); 
    if ((interfaceOrientation == UIDeviceOrientationLandscapeLeft)) NSLog(@"Left"); 
    if ((interfaceOrientation == UIDeviceOrientationPortrait)) NSLog(@"Up"); 
    if ((interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)) NSLog(@"Down"); 
    return YES; 
} 
+0

옵션 1을 사용하면 좋습니다. 해당 코드에서 방향을 검색하고 방향에 따라 if/else 문을 사용하려면 어떻게합니까? –

2
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation; 
+0

이것은 나를 위해 아무 것도하지 않았다. –

+0

오리엔테이션을받지 못했습니까? –

+0

사용 방법이 없습니다. 방금 NSLog 방향을 추가하고 아무것도 얻지 못했습니다. 또한 방위가 바뀔 때마다 지정된 메소드를 호출해야합니다. –