gpt4 book ai didi

ios - 在 iMessage 应用程序中检查横向/纵向方向(扩展)

转载 作者:行者123 更新时间:2023-11-30 12:22:25 25 4
gpt4 key购买 nike

见过很多检查方向的解决方案,但奇怪的是,没有一个有效!!

下面是代码片段,

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

用于设置 View 的另一种方法是,

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

另一件事是,该图像未居中。我该怎么办?同样,解决方案太多,但没有任何效果。

不确定我是否做错了什么。 :-/

最佳答案

这可能是因为 viewWillTransition 在 View 实际翻转之前执行。如果您在 viewWillTransition block 内执行简单的 print("height width\(view.frame.height)\(view.frame.width)") 操作,您将会看到。

关于ios - 在 iMessage 应用程序中检查横向/纵向方向(扩展),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44632424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com