Home Auto rotating code works on iPhone but not on iPad
Reply: 1

Auto rotating code works on iPhone but not on iPad

IOS Guy
1#
IOS Guy Published in 2017-11-14 19:03:37Z

This is the code that only works on the iphone. I am making a universal app that runs on both devices, so it it the identical app.

**//Automatically rotates the view to landscape
    let orientation: UIDeviceOrientation = UIDevice.current.orientation
    //If landscape right the rotate right
    if orientation == UIDeviceOrientation.landscapeLeft
    {
        UIView.animate(withDuration: 0.5, animations:
            {
                () -> Void in
                let value = UIInterfaceOrientation.landscapeRight.rawValue
                UIDevice.current.setValue(value, forKey: "orientation")
        })


    }
    else
    {
        UIView.animate(withDuration: 0.5, animations:
            {
                () -> Void in
                let value = UIInterfaceOrientation.landscapeLeft.rawValue
                UIDevice.current.setValue(value, forKey: "orientation")
        })

    }**
whistler
2#
whistler Reply to 2017-11-14 19:20:19Z

Here's one possibility for you to check...

In the project's settings, under the General tab for a build target, there's the Deployment Info section where you select the "Devices" option (that you probably have on "Universal"). Below that is the Device Orientation selection. There's one, um, interesting feature here.

If you check some orientations when Devices is on Universal, it only applies the setting to the iPhone version. If you toggle the Devices selection to iPad, the options will likely be different. What you need to do is switch the selection to iPhone, apply the orientations you want there, switch it to iPad, apply orientations again, and then finally set Devices to Universal.

I have a hunch (not tested with your code) that if you try to apply an orientation that is not supported here, your code will do nothing.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338363 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO