1
[[UIApplication sharedApplication] statusBarOrientation]을 사용하여 방향이 바뀌면보기가 변경되는 앱이 있습니다. 아이폰에서는 작동하지만 아이 패드에서는 풍경이 아닌 초상화와 인물 대신 풍경을 제공한다. iPad iOS7 오리엔테이션 문제
- I의 UIDeviceOrientationDidChangeNotification의 외부 getRelevantFrame 메소드 호출, 그것은 정확한 프레임을 리턴한다.
- 알림에 응답 할 때 반대 프레임 (가로 방향 인 경우 세로 방향, 반대 방향 인 경우)이 반환됩니다.
편집 : : 중고 rob5408의 조언 - 두 버전 (아이팟/아이폰 + 아이 패드) 같은 코드 만 아이 패드 버전 여기
에이 유일한 휴식을 사용 나는 관련 프레임을 계산하는 데 사용되는 코드는 . UI_USER_INTERFACE_IDIOM()을 사용하도록 변경되었습니다. 여기
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
나는 방향 변경을 읽는 데 사용되는 코드는 다음과 같습니다 :
+ (CGRect)getRelevantFrame {
//Get orientation
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { //iPhone/iPod
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
return [self frameiPhoneLandscape];
}
else {
return [self frameiPhonePortrait];
}
} else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { //iPad
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"iPad Landscape");
return [self frameiPadLandscape];
}
else {
NSLog(@"iPad Portrait");
return [self frameiPadPortrait];
}
}
return CGRectMake(0, 0, 0, 0);
}
여기 내가 사용하는 통지는
- (void) didRotate:(NSNotification *)notification
{
NSLog(@"Parent: %@", self.parentController);
if(self.parentController) {
[self setFrame:[TASFrames getRelevantFrame]];
}
}
보기 경계를 사용하는 대신 자신을 단단히하고'UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad'을 사용하십시오. 아마도 문제가 해결되지는 않지만 앞으로 문제가 해결 될 것입니다. – rob5408
조언 해 주셔서 감사합니다. 나는 그것을 앞으로 확실히 사용할 것이다. – FireDragonMule