2017-04-07 23 views
2

我有一个按钮,在我的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) 
+0

是它仅发生第一次或所有的t输入法? –

+0

@DharmbirSingh只有第一次,我再次按下它的作品 – thelegendary3

回答

1

好像你还没有在厦门国际银行设置图像按钮,在视图中设置你的形象做像

负载希望它会工作

button.setImage(#imageLiteral(resourceName: "play"), for: .normal) 
+0

作品!这是如何解决它?会喜欢解释! – thelegendary3

+0

@ thelegendary3实际上,它是第一次,其他部分我认为你没有在xib的按钮上设置图像,然后它会来,如果部分..希望你能明白:) –

+0

@ thelegendary3如果你想学习移动技术( iOS和Android)请亲切订阅我的YouTube频道** https://www.youtube.com/channel/UCA5HRmlkT7bqbO56EIlT0UQ** –

相关问题