3

iPad 앱에서 UISplitViewController에 문제가 발생했습니다. UISplitView 내부의 UINavigationController를 사용하여 간단한 탐색 트리를 만들려고합니다. 나는이해야 할 다음과 같은 기본 코드를 사용했습니다 :이 코드는 성공적으로 탐색 컨트롤러에보기를 밀어UISplitViewController가 UINavigationController를 사용하려고 시도한 후 자동 회전을 중지합니다.

#import "NavController.h" 

@implementation NavController 

@synthesize navigationController; 

- (void) awakeFromNib { 
    UIViewController *testController = [[UIViewController alloc] init]; 
    UITableView *tableView = [[UITableView alloc] init]; 

    [testController setView: tableView]; 

    [navigationController pushViewController: testViewController 
            animated: YES]; 

} 

@end 

NavController.h

@interface NavController : NSObject { 
    /* 
    * This is connected properly to the UINavigationController in the 
    * UISplitViewController through Interface Builder. 
    */ 

    UINavigationController *navigationController; 

} 

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 

@end 

NavController.m을, 나는 탐색 할 수 있습니다 다시 버튼을 사용하여, 그러나, 내 문제는 사실이 일어난 후 내 UISplitViewController 더 이상 자동 회전 또는 세로 위치에서 전혀 회전 함께 발생합니다. 이 코드를 제거하면 뷰가 푸시되지 않습니다. 예상대로 작동합니다.

내가 잘못하고있는 것이 무엇인가? 나는 이것을 올바른 방향으로 가고 있습니까?

도움 주셔서 감사합니다.

답변

1

이것은 나에게 절대적으로 열매를 맺게했다. 나는 그것을 작동하게 만든 몇 가지 일을했지만 나의 해결책에 대해 행복하지 않다. 1) 나는 그것을 정말로 이해하지 못하고 2) 해커처럼 보인다.

@interface UITabBarController (MyApp) 
@end 

@interface UINavigationController (MyApp) 
@end 

@implementation UITabBarController (MyApp) 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    return YES; 
} 
@end 

@implementation UINavigationController (MyApp) 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    return YES; 
} 
@end 

이것은 대부분 일 :

나는 내 애플 대리자 (내하는 .m 파일)이 추가되었습니다. 자동 회전하지 않는 뷰의 경우 변형을 사용하여 수동으로 뷰를 회전해야했습니다. 나는 다음과 같이했다 :

- (void)deviceOrientationDidChangeWithAnimation:(BOOL)animated { 
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

    if (orientation == oldOrientation) { 
     return; 
    } 

    if (animated) { 
     CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration; 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:duration]; 
     [UIView setAnimationDidStopSelector:@selector(orientationChanged)]; 
    } 

    [self sizeToFitOrientation:YES]; 

    if (animated) { 
     [UIView commitAnimations]; 
    } 

    oldOrientation = orientation; 
} 

- (CGAffineTransform)transformForOrientation { 
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
    if (orientation == UIInterfaceOrientationLandscapeLeft) { 
     return CGAffineTransformMakeRotation(M_PI*1.5); // rotated CCW 
    } else if (orientation == UIInterfaceOrientationLandscapeRight) { // CW 
     return CGAffineTransformMakeRotation(M_PI/2); 
    } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) { // CCW 
     return CGAffineTransformMakeRotation(-M_PI); 
    } else { // CW 
     return CGAffineTransformIdentity; 
    } 
} 

- (void)sizeToFitOrientation:(BOOL)transform { 
    if (transform) { 
     self.view.transform = CGAffineTransformIdentity; 
    } 

    CGRect frame = [UIScreen mainScreen].applicationFrame; 
    CGPoint center = CGPointMake(frame.origin.x + ceil(frame.size.width/2), frame.origin.y + ceil(frame.size.height/2)); 

    CGFloat width = frame.size.width - 0 * 2; 
    CGFloat height = frame.size.height - 0 * 2; 

    UIInterfaceOrientation _orientation = [UIApplication sharedApplication].statusBarOrientation; 
    if (UIInterfaceOrientationIsLandscape(_orientation)) { 
     self.view.frame = CGRectMake(0, 0, height, width); 
    } else { 
     self.view.frame = CGRectMake(0, 0, width, height); 
    } 
    self.view.center = center; 

    if (transform) { 
     self.view.transform = [self transformForOrientation]; 
    } 
} 

희망이있다. 그리고 누군가 내가 실수 한 것을 지적 할 수 있다면 (또는 내가 영속시키는 나쁜 것들), 나는 배워서 기쁠 것입니다. :)

+0

흥미 롭습니다. UINavigationController를 자동으로 회전하도록 설정하는 방법에 대해서는 생각해 본 적이 없습니다. 나는 이것을 도전적으로 시도 할 것이다. UISplitView를 사용하는 것이 더 이해하기를 바랍니다. 답변 해 주셔서 감사합니다! –

+0

오늘 밤이 기회를 놓치지 마십시오. 내 UINavigationController 하위 클래스 및 자동 회전을 사용하려면 필요한 메서드를 추가했습니다. 이제 완벽하게 작동합니다! 지금까지 수동 회전보기를 수행 할 필요가 없었습니다. 당신의 솔루션에 대해 대단히 감사합니다! –

+0

그게 좋습니다! 나는 아직도 그것이 왜 효과가 있는지는 잘 모르지만 나는 그것이 기쁘다. :) – donkim

관련 문제