Fix blurry map view in landscape on iPad (due to an orientation-varying scale factor) (#4373)

This commit is contained in:
Albin Törnqvist
2026-07-09 23:56:28 +02:00
committed by GitHub
parent ad258ded1c
commit e3c81d607a

View File

@@ -1,17 +1,31 @@
#import "MLNDisplayUtils.h"
CGFloat MLNEffectiveScaleFactor(CGSize nativePixelBounds, CGSize logicalPointBounds) {
// `nativeBounds` is always portrait-up while `bounds` rotates with the interface orientation,
// so pair short side with short side to keep the ratio orientation independent.
CGFloat nativeShortSide = MIN(nativePixelBounds.width, nativePixelBounds.height);
CGFloat pointShortSide = MIN(logicalPointBounds.width, logicalPointBounds.height);
return pointShortSide > 0.0 ? nativeShortSide / pointShortSide : 0.0;
}
CGFloat MLNEffectiveScaleFactorForView(id viewOrNil) {
#if TARGET_OS_IPHONE || TARGET_OS_TV
UIView *view = (UIView *)viewOrNil;
UIScreen *screen = view.window.screen ?: [UIScreen mainScreen];
CGFloat logicalToPixelRatio = screen.nativeBounds.size.width / screen.bounds.size.width;
// `nativeScale` is orientation-independent and accounts for Display Zoom (unlike `scale`).
if ([screen respondsToSelector:@selector(nativeScale)] && screen.nativeScale > 0.0) {
return screen.nativeScale;
}
CGFloat logicalToPixelRatio =
MLNEffectiveScaleFactor(screen.nativeBounds.size, screen.bounds.size);
if (logicalToPixelRatio > 0.0) {
return logicalToPixelRatio;
}
return [screen respondsToSelector:@selector(nativeScale)] ? screen.nativeScale : screen.scale;
return screen.scale;
#elif TARGET_OS_OSX