gpt4 book ai didi

swift - 在特定持续时间后删除 subview

转载 作者:行者123 更新时间:2023-11-30 10:15:59 29 4
gpt4 key购买 nike

我显示了一个 subview ,其中包含 subview 、图像和消息。我需要在特定的持续时间/时间(5秒)后快速删除此 subview 。 subview 的代码如下:

     var HideView = UIView (frame: CGRectMake(0 , 0, 320, 480));
HideView.backgroundColor = UIColor(red:0.0, green:0.0, blue:0.0, alpha:0.6);
var ErrorView = UIView (frame: CGRectMake(0, 40, 320, 70));
ErrorView.backgroundColor = UIColor(red:0.8, green:0.376, blue:0.094, alpha:1.0);
ErrorView.clipsToBounds = true;
ErrorView.layer.shouldRasterize = true
HideView.addSubview(ErrorView)

var ErrorImageView = UIImageView(frame: CGRectMake(5, 5, 30, 30));
var ErrorImage = UIImage(named: "error_icon_white.pdf");
ErrorImageView.image = ErrorImage;
ErrorView.addSubview(ErrorImageView)

var ErrorLabel = UILabel (frame: CGRectMake(50, 0, 270, 70));
ErrorLabel.backgroundColor = UIColor.clearColor();
ErrorLabel.textColor = UIColor.whiteColor()
ErrorLabel.font = UIFont(name: "Gotham", size: 1)
ErrorLabel.numberOfLines = 3
var errmsg = "Hello world"
ErrorLabel.text = errmsg;
ErrorView.addSubview(ErrorLabel)
self.view.addSubview(HideView);

我能达到这个要求吗?如果是的话怎么办?提前致谢。

最佳答案

添加 subview 后,添加一个计时器,以便在所需的时间段(5 秒)后触发

var timer = NSTimer.scheduledTimerWithTimeInterval(NSTimeInterval(5.0), target: self, selector: "timeExpired", userInfo: nil, repeats: false)

然后,您可以在“timeExpired”函数中执行您喜欢的任何操作:

func timeExpired() {
println("time expired")
// yoursubview.removeFromSuperview()
}

关于swift - 在特定持续时间后删除 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29916633/

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