我有一个按钮,在我的UITabBar
(自定义)和按钮被点击时的动画不会执行,直到你按两次。我在第一次尝试中使用了print的打印语句,但我不确定它为什么不在第一次尝试中执行动画。这里是我的代码:直到你第二次按下UI按钮才会执行动作
func menuButtonAction(sender: UIButton) {
if sender.currentImage == #imageLiteral(resourceName: "play") {
UIView.animate(withDuration: 0.3, animations: {
sender.setImage(#imageLiteral(resourceName: "playbutton2"), for: .normal)
self.button2.frame = CGRect(x: self.tabBar.center.x, y: self.tabBar.center.y - 100, width: self.buttonimage.size.width, height: self.buttonimage.size.height)
self.view3.alpha = 0.6
})
} else {
sender.setImage(#imageLiteral(resourceName: "play"), for: .normal)
UIView.animate(withDuration: 0.3, animations: {
self.button2.center = self.button.center
self.view3.alpha = 0
})
}
print("Middle Button was just pressed!")
}
我通过像这样的目标运行此功能在viewWillAppear
:
button.addTarget(self, action: #selector(self.menuButtonAction(sender:)), for: .touchUpInside)
是它仅发生第一次或所有的t输入法? –
@DharmbirSingh只有第一次,我再次按下它的作品 – thelegendary3