简体   繁体   English

尝试以横向检测iPhone 6 Plus

[英]Trying to detect iPhone 6 Plus in landscape orientation

I have a today widget for my app and I have been setting the layout of objects in code (Not using auto-layout) however, I need to detect when a user is using an iPhone 6 Plus. 我的应用今天有一个小部件,并且已经在代码中设置了对象的布局(不使用自动布局),但是,我需要检测用户何时使用iPhone 6 Plus。 The reason for this is because in notification centre on the 6 Plus, there is a border around the edge which cuts off the labels in my widget (in landscape). 这样做的原因是因为在6 Plus的通知中心中,边缘周围有一个边框,该边框切断了我的小部件(横向)中的标签。

The problem is that I have been having issues trying to figure out what height value the screen is in landscape. 问题是我一直在试图找出屏幕在横向上的高度值时遇到问题。

This is the code I have right now: 这是我现在拥有的代码:

        var height = UIScreen.mainScreen().bounds.size.height

    if UIDevice.currentDevice().orientation.isLandscape && height == 414 {
        totalBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
        currentBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
        budgetNameDisplay.frame.origin.x = 80
        warningLabel.center = view.center
        button.frame = CGRectMake(0, 0, view.bounds.width, view.bounds.height)
    }

Is this the correct value for the screen height in landscape? 这是横向屏幕高度的正确值吗? If so, why are the labels still not moving? 如果是这样,为什么标签仍然没有移动?

Your code is good but UIDevice.currentDevice().orientation.isLandscape just does not get you correct value. 您的代码不错,但是UIDevice.currentDevice()。orientation.isLandscape只是无法为您提供正确的值。

Seems like there is no bullet-proof solution to detect device orientation for Extensions. 好像没有防弹解决方案来检测扩展的设备方向。

Look at this answer for possible workaround - https://stackoverflow.com/a/26023538/2797141 查看此答案以获取可能的解决方法-https: //stackoverflow.com/a/26023538/2797141

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM