Coder Social home page Coder Social logo

isZoomed() Not working about devicekit HOT 8 CLOSED

devicekit avatar devicekit commented on June 26, 2024
isZoomed() Not working

from devicekit.

Comments (8)

kiwo12345 avatar kiwo12345 commented on June 26, 2024

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.

dennisweissmann avatar dennisweissmann commented on June 26, 2024

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.

kiwo12345 avatar kiwo12345 commented on June 26, 2024

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.

vvit avatar vvit commented on June 26, 2024

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.

Zandor300 avatar Zandor300 commented on June 26, 2024

@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.

vvit avatar vvit commented on June 26, 2024

I see, thanks.
The problem is I need to check it on a real 'Plus' device which I don't have.

from devicekit.

Zandor300 avatar Zandor300 commented on June 26, 2024

@vvit I will check on my old 6s Plus for you when you’ve prepared the PR. ;)

from devicekit.

vvit avatar vvit commented on June 26, 2024

@Zandor300 thanks, pls check #195

from devicekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.