gpt4 book ai didi

ios - 作为 subview 添加到应用程序窗口的 UIView 在设备旋转时不旋转

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

我创建了 UIView 的扩展并创建了一个 ActivityIndi​​catorView 并将其作为 subview 添加到 UIApplication Window。现在,当设备旋转时,UIViewController 也会旋转,而不是这个 ActivityIndi​​catorView

internal extension UIView{

func showActivityViewWithText(text: String?) -> UIView{

let window = UIApplication.sharedApplication().delegate?.window!!
let baseLineView = window!.viewForBaselineLayout()

let locView = UIView(frame:window!.frame)
locView.backgroundColor = UIColor.clearColor()
locView.center = window!.center

baseLineView.addSubview(locView)
baseLineView.bringSubviewToFront(locView)

let overlay = UIView(frame: locView.frame)
overlay.backgroundColor = UIColor.blackColor()
overlay.alpha = 0.35

locView.addSubview(overlay)
locView.bringSubviewToFront(overlay)

let hud = UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge)
hud.hidesWhenStopped = true
hud.center = CGPoint(x: locView.frame.size.width/2,
y: locView.frame.size.height/2)

hud.transform = CGAffineTransformMakeScale(1, 1)
hud.color = UIColor.redColor()
hud.startAnimating()

locView.addSubview(hud)
locView.bringSubviewToFront(hud)
}

最佳答案

可能问题出在错过自动调整大小掩码?尝试添加:

hud.autoresizingMask = [ .flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin ]

我想,由于您的 hudlocView 的 subview ,autoresizingMask 也是 locView 所必需的。

关于ios - 作为 subview 添加到应用程序窗口的 UIView 在设备旋转时不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40152218/

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