2017-06-19 19 views
0

オリエンテーションをチェックするための解決策はたくさんありましたが、不思議なことに何もありません!!以下iMessageアプリ(拡張機能)で横向き/縦向きを確認

は、もう一つは、この画像が中央されていない、ということであるビューがあるセットアップするために使用される他の方法、

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) 
} 

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() 
    } 
} 

、コードスニペットです。それについてどうすればいいですか?再び、あまりにも多くのソリューションが、何も仕事をしません。

私が間違っているかどうかはわかりません。 -/

答えて

0

これは、ビューが実際に反転する前にviewWillTransitionが実行されている可能性があります。 viewWillTransitionブロック内に単純なprint("height width \(view.frame.height) \(view.frame.width)")を実行すると、表示されます。

関連する問題