1

My previous view (CaptureVC) doesn't autorotate, so it only has a portrait orientation. My second view that it transitions into (ManageCaptureVC) does autorotate, and while it is doing a fading transition into it, CaptureVC is suddenly rotated while fading if the device is in landscape. How can this be avoided or compensated for?

To be more thorough, it is a scaling animation, then a fading animation into the new view controller (ManageCaptureVC):

UIView.animate(withDuration: 0.3, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: {
    self.view.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
}, completion: { (finished: Bool) in
    // Here is where CaptureVC rotates while fading into ManageCaptureVC
    let transition = CATransition()
    transition.duration = 0.5
    transition.type = kCATransitionFade
    transition.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseIn)
    self.present(manageCaptureVC, animated: false, completion: nil)
})

In my app delegate, I overrode these two functions:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController) {
        if (rootViewController.responds(to: Selector(("canRotate")))) {
            // Unlock landscape view orientations for this view controller if it is not currently being dismissed
            if !rootViewController.isBeingDismissed{
                return .all
            }
        }
    }

    // Only allow portrait (standard behaviour)
    return .portrait
}

private func topViewControllerWithRootViewController(rootViewController: UIViewController!) -> UIViewController? {
    if (rootViewController == nil) {
        return nil
    }
    if (rootViewController.isKind(of: UITabBarController.self)) {
        return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UITabBarController).selectedViewController)
    } else if (rootViewController.isKind(of: UINavigationController.self)) {
        return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UINavigationController).visibleViewController)
    } else if (rootViewController.presentedViewController != nil) {
        return topViewControllerWithRootViewController(rootViewController: rootViewController.presentedViewController)
    }
    return rootViewController
}

And ManageCaptureVC I added:

@objc func canRotate(){}

So that it so it responds to autorotating.

Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90
  • Check this Answer. it's possible help you: https://stackoverflow.com/questions/41702940/how-to-rotate-only-one-view-controller-to-landscape-orientation-in-ios-swift-3/41702941#41702941 – gandhi Mena Apr 30 '18 at 21:46
  • Both orientation options work for both view controllers, it’s just the fading transition that looks messed up, possibly because it captures an image of the current view controller, rotates the second view, then fades. – Chewie The Chorkie May 01 '18 at 14:18
  • That answer looks to be almost identical to what I'm using in my question. I updated the question with the other part I'm using in my delegate which is the same as in that link. – Chewie The Chorkie May 01 '18 at 14:42

0 Answers0