axiixc에서 제안한 해결책은 일반적으로 문제에 따라 다르므로 look at his answer이어야합니다. 그러나 이것은 내 문제를 해결하지 못했습니다. 나는 UINavigationController
을 가지고 있는데, 뷰 컨트롤러의 뷰를 인덱스 0의 서브 뷰로 삽입했다.이 방법은 뷰가 뒤쪽에있을 것이다. 그 다음에 나는 UINavigationBar
을 드래그 가능하게 만들었습니다. 드래그 할 때 뒤쪽에있는 뷰를 드러내도록했습니다. 그러면 가장 앞쪽에있는보기가 내비게이션 막대와 함께 움직입니다. axiixc에서 제안한 것처럼 iOS 5가 도입 된 View Controller Containment API로이 기능을 사용할 수 없었습니다.
대신 내비게이션 컨트롤러에서보기를 제거하고 앱이 시작될 때 UIWindow
에 직접 추가했으며이보기의 회전을 직접 처리하고 다른 모든보기에서 순환 게재를 사용하지 않도록 설정했습니다 (즉, 네비게이션 컨트롤러).
이
내가
UIDeviceOrientationDidChangeNotification
에 등록 된 바로 그 후, 그 다음
self.revealViewController = [[RevealViewController alloc] init];
[self.window insertSubview:self.revealViewController.view atIndex:0];
-application:didFinishLaunchingWithOptions:
에서보기를 추가하는 방법입니다.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
내 didRotate:
은 다음과 같습니다
- (void)didRotate:(NSNotification *)notification
{
// Only rotate if the view is revealed
if (self.revealNavigationController.isViewRevealed)
{
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
[self updateForDeviceOrientation:orientation animated:YES];
}
}
내가 -updateForDeviceOrientation:animated:
- (void)updateForDeviceOrientation:(UIDeviceOrientation)orientation animated:(BOOL)animated
{
CGFloat degrees = 0.0f;
switch (orientation)
{
case UIDeviceOrientationLandscapeLeft:
degrees = 90.0f;
break;
case UIDeviceOrientationLandscapeRight:
degrees = -90.0f;
break;
case UIDeviceOrientationPortrait:
degrees = 0.0f;
break;
default:
break;
}
CGFloat duration = (animated) ? [UIApplication sharedApplication].statusBarOrientationAnimationDuration : 0.0f;
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:duration animations:^{
// Rotate view
weakSelf.revealViewController.view.transform = CGAffineTransformIdentity;
weakSelf.revealViewController.view.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(degrees));
// Resize view for rotation
CGFloat width, height;
if (UIDeviceOrientationIsLandscape(orientation))
{
width = MAX(CGRectGetWidth(weakSelf.revealViewController.view.bounds), CGRectGetHeight(weakSelf.revealViewController.view.bounds));
height = MIN(CGRectGetWidth(weakSelf.revealViewController.view.bounds), CGRectGetHeight(weakSelf.revealViewController.view.bounds));
}
else
{
width = MIN(CGRectGetWidth(weakSelf.revealViewController.view.bounds), CGRectGetHeight(weakSelf.revealViewController.view.bounds));
height = MAX(CGRectGetWidth(weakSelf.revealViewController.view.bounds), CGRectGetHeight(weakSelf.revealViewController.view.bounds));
}
CGSize newSize = CGSizeMake(width, height);
CGRect viewBounds = weakSelf.revealViewController.view.bounds;
viewBounds.size = newSize;
weakSelf.revealViewController.view.bounds = viewBounds;
CGRect viewFrame = weakSelf.revealViewController.view.frame;
viewFrame.size = newSize;
weakSelf.revealViewController.view.bounds = viewFrame;
}];
}
인가 전화 (이것은 미안 해요 다시 찾을 지금 드릴 수 없습니다에 StackOverflow에 다른 답변, 영감) 사용자가 뒤로보기를 표시하고 옆으로 회전 한 다음 숨기고 기본보기가 여전히 옆으로 보이거나 화면이 꺼져 있어도 기본보기가 회전되는 문제는 무엇입니까? – axiixc
@axiixc 화면이 꺼져있을 때 기본보기가 회전되는 것이 문제입니다. 뷰 컨트롤러는 방향 변경을 지원하지 않으므로 다시보기를 표시하고 가로로 회전하고 세로로 회전하여 다시보기를 숨기면 기본보기가 표시되고 기본보기가 엉망이됩니다. 이상적으로는 기본보기를 회전하는 것이 불가능하기를 바랄 것입니다. 이렇게하면 두 가지 문제점을 모두 해결할 수 있습니다. 따라서 사용자가 백 뷰를 표시하고 옆으로 회전하여 숨기면 기본 뷰는 여전히 세로입니다. – simonbs