당신의하는 .m 파일에서이 밖으로 시도 : 함수에서
- (void)updateLayoutForNewOrientation:(UIInterfaceOrientation)orientation
{
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
// Portrait
[object setFrame:CGRectMake(...)];
// Do the same for the rest of your objects
}
else
{
// Landscape
[object setFrame:CGRectMake(...)];
// Do the same for the rest of your objects
}
}
, 당신은 세로 및 가로를 들어, 뷰에서 각 개체의 위치를 정의했습니다.
그런 다음 처음에 기능을 호출하려면 viewWillAppear
이라고 부릅니다. 또한
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateLayoutForNewOrientation:self.interfaceOrientation];
}
를위한 당신이 회전 할 때 :보기는 시작에 사용할 방향을 결정 나는 오리엔테이션에 관해서 좀 더 사용자 정의 모양을 필요로하는 경우
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
[self updateLayoutForNewOrientation:self.interfaceOrientation];
}
이것은 내가 가지고 접근 방식이다. 그게 너에게 도움이되기를 바랍니다.
편집 : 하나의 UIViewController에서 두 UIViews, 세로 하나와 풍경의 또 다른를 사용하는 경우
, 당신은 다음과 같이 할 코드의 첫 번째 부분을 바꿀 것 :이
- (void)updateLayoutForNewOrientation:(UIInterfaceOrientation)orientation
{
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
// Portrait
portraitView.hidden = NO;
landscapeView.hidden = YES;
}
else
{
// Landscape
portraitView.hidden = YES;
landscapeView.hidden = NO;
}
}
이 편집 된 샘플과 원본 사이에 장단점이 있습니다. 원래는 모든 객체를 코드화해야하지만이 편집 된 샘플에서는이 코드 만 있으면 충분합니다. 그러나 본질적으로 객체를 세로보기 용으로, 가로보기 용으로 두 번 할당해야합니다.
답장을 보내 주셔서 감사합니다. 나는 CGRectMake에 들어가는 것이 약간 혼란 스럽다. 왜냐하면 현재 스토리 보드를 사용하여 두 가지보기를 만들었 기 때문입니다. 가로 및 다른 하나에 대 한 초상화입니다. 두 개의 뷰를 코드에 연결하는 방법 – GoCrazy
CGRectMake는 인터페이스 객체의 위치와 CGRectMake (x-position, y-position, width, height) 객체의 크기를 정의하는 데 사용됩니다. - 두 개의 UIView를 사용하는 경우 수행 할 작업을 반영하여 내 대답을 편집합니다. – Scott
감사합니다 숀 훌륭한 것입니다. 많이 감사합니다 – GoCrazy