We saw many solutions for checking orientation, but, strangely enough, no one works !!
Below is a snippet of code,
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { let screenSize = UIScreen.main.bounds let screenWidth = screenSize.width let screenHeight = screenSize.height print("Screen Width = \(screenWidth)") print("Screen Height = \(screenHeight)") if (screenWidth > screenHeight) { print("Landscape") alertView.removeFromSuperview() messageView.addGestureRecognizer(tapTextView) } else { print("Portrait") setupLandscapeAlertView() } }
Another way that is used to adjust the view is to
fileprivate func setupLandscapeAlertView() { messageView.removeGestureRecognizer(tapTextView) alertView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)) alertView.backgroundColor = UIColor.clear alertView.isUserInteractionEnabled = false let transparentView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.height, height: self.view.frame.width)) transparentView.backgroundColor = UIColor.gray transparentView.backgroundColor = transparentView.backgroundColor!.withAlphaComponent(0.6) transparentView.isUserInteractionEnabled = false alertView.addSubview(transparentView) let blurEffect = UIBlurEffect(style: .regular) let blurredEffectView = UIVisualEffectView(effect: blurEffect) blurredEffectView.frame = transparentView.bounds blurredEffectView.isUserInteractionEnabled = false alertView.addSubview(blurredEffectView) let imageView = UIImageView(image: UIImage(named: "LandscapeAlert")) imageView.frame = CGRect(x: 70, y: 75, width: imageView.frame.width, height: imageView.frame.height) imageView.contentMode = UIViewContentMode.scaleAspectFit imageView.contentMode = UIViewContentMode.center imageView.isUserInteractionEnabled = false alertView.addSubview(imageView) self.view.addSubview(alertView) }
Another thing is that this image is not centered. How can I do it? Again, there are too many solutions, but it does nothing.
Not sure if I am doing something wrong .: - /
ios swift swift3 uiimageview orientation
Shyam
source share