2017-04-07 15 views
2

ボタンをクリックしたときに私の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) 
+0

が、それは非常に最初の時間が起きたり、すべてのtについてされて働くことを願っていますイメス? –

+0

@DharmbirSingh初めて初めて、もう一度それを押すとすぐに – thelegendary3

答えて

1

あなたがやったXIBのボタンに画像を設定するので、ビューで画像を設定していないようです

のような負荷は、それが

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

Works !!!これでどのように修正されましたか?説明が大好き! – thelegendary3

+0

@ thelegendary3実際にそれ以外の部分は非常に初めてです、私はあなたがxibのボタンに画像を設定していないと思うし、それが部分的に来るだろう..あなたが理解できることを願って:) –

+0

@ thelegendary3あなたはモバイル技術iOSとAndroid)が自分のYouTubeチャンネルを親切に登録する** https://www.youtube.com/channel/UCA5HRmlkT7bqbO56EIlT0UQ** –

関連する問題