iOS 7과 iOS 8에서 다음 코드를 실행했습니다.
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landscape = (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight);
NSLog(@"Currently landscape: %@, width: %.2f, height: %.2f",
(landscape ? @"Yes" : @"No"),
[[UIScreen mainScreen] bounds].size.width,
[[UIScreen mainScreen] bounds].size.height);
다음은 iOS 8의 결과입니다.
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 568.00, height: 320.00
iOS 7의 결과와 비교 :
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 320.00, height: 568.00
이 변경 사항을 명시한 문서가 있습니까? 아니면 iOS 8 API의 임시 버그입니까?
답변
예, iOS8에서는 버그가 아니라 방향에 따라 다릅니다. 자세한 내용은 WWDC 2014의 세션 214를 검토 할 수 있습니다. “iOS 8의 컨트롤러 고급보기”
프레젠테이션에서 인용 :
UIScreen은 이제 인터페이스 지향입니다 :
- [UIScreen 경계] 이제 인터페이스 지향
- [UIScreen applicationFrame] 이제 인터페이스 지향
- 상태 표시 줄 프레임 알림은 인터페이스 지향
- 키보드 프레임 알림은 인터페이스 지향
답변
예, iOS8에서는 방향에 따라 다릅니다.
이전 버전의 OS를 지원해야하는 앱의 경우이 문제를 해결하기 위해 Util 메소드를 작성했습니다.
+ (CGSize)screenSize {
CGSize screenSize = [UIScreen mainScreen].bounds.size;
if ((NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
return CGSizeMake(screenSize.height, screenSize.width);
}
return screenSize;
}
답변
그렇습니다. 실제로 화면 크기는 iOS 8에서 방향에 따라 다릅니다. 그러나 때로는 세로 방향으로 크기를 고정하는 것이 좋습니다. 내가하는 방법은 다음과 같습니다.
+ (CGRect)screenBoundsFixedToPortraitOrientation {
UIScreen *screen = [UIScreen mainScreen];
if ([screen respondsToSelector:@selector(fixedCoordinateSpace)]) {
return [screen.coordinateSpace convertRect:screen.bounds toCoordinateSpace:screen.fixedCoordinateSpace];
}
return screen.bounds;
}
답변
예, 이제 방향에 따라 다릅니다.
위의 답변 중 일부가 방향과 무관하게 화면 크기를 얻는 방법을 선호합니다. 단순하고 방향 코드에 의존하지 않기 때문에 (상태는 호출 된 시간) 또는 버전 확인 중입니다. 새로운 iOS 8 동작을 원할 수도 있지만 모든 iOS 버전에서 안정적으로 작동해야하는 경우 작동합니다.
+(CGSize)screenSizeOrientationIndependent {
CGSize screenSize = [UIScreen mainScreen].bounds.size;
return CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height));
}
답변
내 문제를 해결 한이 질문과 관련하여 화면 너비 및 높이 계산에 사용하는 두 가지 정의가 있습니다.
#define SCREEN_WIDTH (IOS_VERSION_LOWER_THAN_8 ? (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height) : [[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT (IOS_VERSION_LOWER_THAN_8 ? (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.width) : [[UIScreen mainScreen] bounds].size.height)
#define IOS_VERSION_LOWER_THAN_8 (NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1)
iOS 7과 iOS 8을 모두 지원하는 경우이 문제에 가장 적합한 솔루션입니다.
답변
사용할 수 있습니다 nativeBounds
(방향 독립적)
nativeBounds
실제 화면의 경계 사각형으로 픽셀 단위로 측정됩니다. (읽기 전용)
선언 스위프트
var nativeBounds: CGRect { get }
이 사각형은 세로 방향의 장치를 기준으로합니다. 장치가 회전해도이 값은 변경되지 않습니다.
장치 높이 감지 :
if UIScreen.mainScreen().nativeBounds.height == 960.0 {
}
장치 너비 감지 :
if UIScreen.mainScreen().nativeBounds.width == 640.0 {
}
답변
iOS 8 SDK의 버그는 아닙니다. 그들은 경계 인터페이스 방향에 의존했습니다. 그 사실에 대한 일부 참조 또는 문서에 대한 귀하의 질문에 따르면 WWDC 2014의View Controller Advancements in iOS 8
214 세션 을 시청 하는 것이 좋습니다 . 가장 흥미로운 부분은 (의심에 따라) 50:45에서 시작하는 것입니다.Screen Coordinates
