gpt4 book ai didi

ios - Swift UIView 自定义位置

转载 作者:行者123 更新时间:2023-11-29 01:05:21 25 4
gpt4 key购买 nike

对于菜鸟问题​​提前抱歉:

我有下面的功能,可以完美地与一个捕获此 View 覆盖我在屏幕底部的一个按钮。我如何调整此功能以仅在屏幕底部为按钮留出 50 px 的空间。是否可以使用 mainScreen().bounds 并在顶部或底部留一些空间?

func flashColor() {
if let window = self.view{
let screenSize: CGRect = UIScreen.mainScreen().bounds
let v = UIView(frame: screenSize)

v.backgroundColor = colors[i]
v.alpha = 1

if i < 4 {
i += 1
} else {
i = 0
}

window.addSubview(v)
UIView.animateWithDuration(1, animations: {
v.alpha = 0.0
}, completion: {(finished:Bool) in
print(i)
v.removeFromSuperview()
})

}
}

最佳答案

一般来说,最好避免使用 UIScreen.mainScreen().bounds,因为这将返回整个设备屏幕的边界。在分屏多任务处理之前,通常可以假设您的应用程序将接管整个屏幕,但现在情况不再如此。您可以改用 View Controller 的 View 边界。如果你想要一个 View 覆盖 View Controller 的 View ,从顶部到底部上方 50 点,你可以这样说:

func flashColor() {
if let vcView = self.view{
let viewSize: CGRect = CGRect(x:0.0,y:0.0,width:vcView.bounds.size.width,height:vcView.bounds.size.height - 50.0)
let v = UIView(frame: viewSize)

v.backgroundColor = colors[i]
v.alpha = 1

if i < 4 {
i += 1
} else {
i = 0
}

window.addSubview(v)
UIView.animateWithDuration(1, animations: {
v.alpha = 0.0
}, completion: {(finished:Bool) in
print(i)
v.removeFromSuperview()
})

}
}

关于ios - Swift UIView 自定义位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36465026/

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