ボタンをクリックしたときに私のUITabBar
(カスタム)とアニメーションにボタンがあり、2回押すまで実行されません。最初の試行でprintを使用したので、なぜ最初の試行でアニメーションが実行されないのか分かりません。ここに私のコードは次のとおりです。UIボタンが2回目までの操作を実行しません
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