편집 : 질문과 제목을 업데이트했습니다. 문제는 내 자신의 init에 추가 된 UIView가 실제로 회전 이외의 다른 작업을 수행하지 않는다는 것입니다. UIView 회전을 처리해야합니까? 나는 운이없는 [self.overlay addConstraints:[self.view constraints]];
를 시험해 보았다. 나는 이것이 viewDidAppear
안에 [self.overlay setFrame:self.view.frame];
으로 고쳐질지도 모른다는 것을 깨닫는다. 그러나 나는 결코 그 방법 안에서 무엇이든을하지 않을 것이다.UIView를 viewController의 방향으로 회전 시키십시오.
지금까지 Storyboard를 사용하여 내 View Controller를 디자인했습니다. 이번에는 뷰를 표시하기 위해 몇 줄의 코드를 작성하고 있지만 컨트롤러의 init에서 만든 뷰는 내 방향을 고려하지 않을 것 같습니다. Storyboard를 사용하고 ViewController를 이름으로 인스턴스화하면 작동합니다. 자, 내가 생각하는 커스텀 init 메소드를 사용하여 직접 인스턴스화하고있다. 내 사용자의 ViewController 단순히이 초기화 방법과 약간의 회전-대표 있습니다
CustomViewController *cvc = [[CustomViewController alloc] initWithURL: url];
[cvc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:cvc animated:YES completion:nil];
(또는 다른 transitionStyle) :
-(id)initWithURL:(NSURL*)url
{
self = [super init];
if(self)
{
self.overlay = [[UIView alloc] initWithFrame: self.view.frame];
self.overlay.backgroundColor = [UIColor grayColor];
[self.view addSubview:self.overlay];
self.url = url;
}
return self;
}
/* viewDidLoad etc.. */
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
이 모달을 표시하려면를, 나는 현재 표시 컨트롤러에서 이것을 사용
결과는 아래 이미지에 표시됩니다. 회색 영역은 init에 생성 된 CustomViewController 내의 새로운 UIView입니다. 검은 색 영역은 self.view
이며 제대로 정렬됩니다. 세로와 회전을 허용하면 가로 세로로 완벽하게 정렬되지만 가로로 정렬되지는 않습니다. 표시된 모달의 customViewController에서 self.overlay
이 올바르게 회전하지 않습니다. init
메서드 중 하나를 대체하여 일부 규칙을 재정의합니까? 스토리 보드를 통해이를 수행 할 때 가로로 올바르게 표시됩니다.
shouldAutorotate에서 NO를 반환 해보십시오. – danh
@ 단 감사합니다.하지만 문제의 일부는 아닙니다. 회전에 대한 모든 메소드를 제거하더라도 ('initWithURL' 이외의 모든 메소드) 여전히 발생합니다. 유일한 차이점은 세로로 표시되지만 가로로 표시되지 않는다는 것입니다. UIViewController 내부의 UIView는 마치 장치 및 컨트롤러가 가로 방향으로있을 때도 세로 방향으로 유지되는 것처럼 보입니다. – Sti