Need help setting up an interface where rotation is fixed for most elements, but alert and sharing boxes auto-rotate with the device

后端 未结 1 336
伪装坚强ぢ
伪装坚强ぢ 2021-01-23 04:54

I\'m working with Xcode 7 and Swift 2. I am working on an interface with a camera preview layer and controls that display in a manner similar to the native iOS camera app. The c

相关标签:
1条回答
  • 2021-01-23 05:25

    Got it working. I needed to access presentedViewController.view to rotate the alert and share views.

    //used to periodically trigger a check of orientation
    var updateTimer: NSTimer?
    
    //Checks if the device has rotated and, if so, rotates the controls. Also prompts the user that portrait orientation is bad.
    func checkOrientation(timer: NSTimer) {
        //Array of the views that need to be rotated as the device rotates
        var viewsToRotate = [oneView, anotherView]
    
        //This adds the alert or sharing view to the list, if there is one
        if let presentedVC = presentedViewController?.view {
            viewsToRotate.append(presentedVC)
        }
    
        //Rotate all of the views identified above
        for viewToRotate in viewsToRotate {
            switch UIDevice.currentDevice().orientation {
            case UIDeviceOrientation.Portrait:
                viewToRotate.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2))
            case UIDeviceOrientation.PortraitUpsideDown:
                viewToRotate.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
            case UIDeviceOrientation.LandscapeRight:
                viewToRotate.transform = CGAffineTransformMakeRotation(CGFloat(2 * M_PI_2))
            default:
                viewToRotate.transform = CGAffineTransformMakeRotation(CGFloat(0))
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题