Comments (8)
Solution:
if(UIScreen.main.bounds.size.height == 667.0 && UIScreen.main.nativeScale < UIScreen.main.scale){
print("iphone 6 plus")
} else {
print("none zoomed 6 plus")
}
if (UIScreen.main.bounds.size.height == 568.0 && UIScreen.main.nativeScale > UIScreen.main.scale) {
print("zoomed iphone 6")
} else {
print("none zoomed")
}
from devicekit.
Hi @kiwo12345 , thank you so much for taking the time to report and actually finding a workaround for the issue :) 💯 However, I'm really not keen on hardcoding display heights :( Do you by any chance own an iPhone 5, SE, 6 or 7 (not the Plus version)? I only have the 6 Plus, 6s and 7 Plus (and an iPad Pro 12.9") for me to test I found the following:
print(UIScreen.main.nativeBounds)
print(UIScreen.main.bounds)
print(UIScreen.main.scale)
print(UIScreen.main.nativeScale)
iPhone 6/7 Plus not zoomed:
(0.0, 0.0, 1080.0, 1920.0)
(0.0, 0.0, 414.0, 736.0)
3.0
2.60869565217391
iPhone 6/7 Plus zoomed:
(0.0, 0.0, 1080.0, 1920.0)
(0.0, 0.0, 375.0, 667.0)
3.0
2.88
iPhone 6s not zoomed:
(0.0, 0.0, 750.0, 1334.0)
(0.0, 0.0, 375.0, 667.0)
2.0
2.0
iPhone 6s zoomed:
(0.0, 0.0, 750.0, 1334.0)
(0.0, 0.0, 320.0, 568.0)
2.0
2.34375
iPad Pro not zoomed:
(0.0, 0.0, 2048.0, 2732.0)
(0.0, 0.0, 1024.0, 1366.0)
2.0
2.0
iPad Pro zoomed:
(0.0, 0.0, 2048.0, 2732.0)
(0.0, 0.0, 768.0, 1024.0)
2.0
2.66666666666667
So it seems that for 2x devices we can say that if the native scale is larger than the current scale, the device is zoomed (which is what the current code in the framework does).
However, on 3x devices we need to differentiate. I'm currently thinking about something along those lines:
Pseudocode:
if Int(UIScreen.main.scale.rounded()) == 3 {
// Plus-sized
return UIScreen.main.nativeScale > 2.7
} else {
return UIScreen.main.nativeScale > UIScreen.main.scale
}
which also includes a quite arbitrary hardcoded magic number :( I don't know what's better tbh, quick research online showed that both methods (yours and mine) are used.
from devicekit.
Hey @dennisweissmann I think I have a 5s and 5 SE that I can check if you want to. But yeah I agree, not the best to have a hardcoded value : /
from devicekit.
Hi guys, it seems the line
return UIScreen.main.nativeScale > 2.7
no longer works on the Simulator iPhone6/8 12.4. Since the UIScreen.main.nativeScale
is always 3 for non-zoomed display.
Does it support simulators?
I had to modify it to:
return UIScreen.main.nativeScale > 2.7 && UIScreen.main.nativeScale < 3
I can create a PR if needed. Thanks.
@dennisweissmann
from devicekit.
@vvit
Feel free to create a pull request for this issue.
(Dennis isn't working on this project anymore and he has handed it off to @denisenepraunig)
from devicekit.
I see, thanks.
The problem is I need to check it on a real 'Plus' device which I don't have.
from devicekit.
@vvit I will check on my old 6s Plus for you when you’ve prepared the PR. ;)
from devicekit.
@Zandor300 thanks, pls check #195
from devicekit.
Related Issues (20)
- Add Watch Series 7 HOT 2
- Add New Devices - iPhone 14, Apple Watch SE (2nd Gen., Apple Watch Ultra / Series 8 HOT 1
- check pod trunk warnings
- How to get physical Size or scale factor HOT 2
- Old version is installed from CocoaPods HOT 2
- Fast charge device support HOT 1
- Failed SwiftUI preview on macOS HOT 1
- .hasDynamicIsland would be a nice convenience method HOT 1
- Broken HOT 2
- looks smart
- Add property for corner radius value of all curved iOS devices HOT 1
- How Can I save the device to defaults? HOT 1
- Compile xcframework for releases
- List supported iOS versions by device
- Support for building with visionOS SDK
- Deprecated: `UIScreen.main` HOT 1
- Add newly released devices HOT 7
- Privacy manifest files
- No longer compiles on visionOS HOT 2
- Missing 5.1 in CocoaPods HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from devicekit.