正如代码所示,我有一个开启时启动动画的开关,但无论如何都会显示五彩纸屑并且不允许我进行按钮交互!
@IBAction func `switch`(_ sender: UISwitch) {
if(sender.isOn==true){
senderText.text="YAYA!"
supportText.text="we have added a reminder for you"
supportIcon.isHidden=false
support2.isHidden=true
confettiView.startConfetti()
}
else{
senderText.text="OKAY"
supportText.text="you wont be disturbed"
supportIcon.isHidden=true
support2.isHidden=false
}
}
var confettiView: SAConfettiView!
override func viewDidLoad() {
super.viewDidLoad()
confettiView = SAConfettiView(frame: self.view.bounds)
confettiView.colors = [UIColor(red:0.95, green:0.40, blue:0.27, alpha:1.0),
UIColor(red:1.00, green:0.78, blue:0.36, alpha:1.0),
UIColor(red:0.48, green:0.78, blue:0.64, alpha:1.0),
UIColor(red:0.30, green:0.76, blue:0.85, alpha:1.0),
UIColor(red:0.58, green:0.39, blue:0.55, alpha:1.0)]
confettiView.intensity = 0.5
confettiView.type = .Diamond
confettiView.type = .Confetti
view.addSubview(confettiView)
答案 0 :(得分:2)
发生的事情是你的confettiView位于所有其他视图的顶部,并且正在接收所有触摸,防止按钮和开关接收它们
confettiView.isUserInteractionEnabled = false
在confettiView初始化之后插入的这行代码应解决问题,因为五彩纸屑视图将不再拦截所有触摸。
另一种解决方案(取决于您的设计要求)是将所有按钮置于前面,如果您有参考,或者如果您想要定义持续时间的动画,则删除五彩纸屑视图。
也请不要那样
confettiView.type = .Diamond
confettiView.type = .Confetti
将导致类型为.Confetti。考虑删除两个类型assign语句之一。 :)
答案 1 :(得分:0)
您的confettiView
高于所有其他UIView
和UIButton
。
confettiView = SAConfettiView(frame: self.view.bounds)
使您的confettiView
大小与整个屏幕相同。然后,您使用view
将其添加到view.addSubview(confettiView)
。动画后删除confettiView
。
例如:
confettiView.removeFromSuperview()