2016-04-20 9 views
0

私は簡単な質問があります。私はボタンをタップしたいと一度タップし、そのボタンを迅速に同じ画像の黒の&白バージョンにフェードアウトしてから元のカラー画像に5秒以上戻します。これが起こっている間、私は過剰なタップを防ぐためにボタンを無効にしたい。私はボタンを無効にする方法を知っています。私はちょうど残りをする方法を知らない。ボタンをタップすると同じボタンイメージが別のイメージに変更され、元のイメージにフェードバックします

私のコードの提供を開始する場所はわかりません。

var popTime = dispatch_time(DISPATCH_TIME_NOW, animationDuration * NSEC_PER_SEC) 
dispatch_after(popTime, dispatch_get_main_queue(), {() -> Void in 
    button.userInteractionEnabled = true 
}) 
+1

画像を通常状態と無効状態に設定し、この記事で説明したようにアニメーション化してみましたか? http://stackoverflow.com/a/36244618/491980? – EmptyStack

答えて

1

あなたはこれを使用することができます

@IBOutlet weak var logoIndicator: UIButton! 



override func viewDidLoad() { 
    super.viewDidLoad() 


} 



@IBAction func logoEraseAll(sender: AnyObject) { 

    onTapped() 



} 

func onTapped(){ 

    let afterTapped = UIImage(named: "grey.png") as UIImage! 
    self.logoIndicator.setImage(afterTapped, forState: .Normal) 
    logoIndicator.enabled = false 
    delay(2) { 
     self.transitionBack() 
    } 
} 
func delay(delay:Double, closure:()->()) { 

    dispatch_after(
     dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), closure) 
} 

func transitionBack(){ 

    UIView.transitionWithView(logoIndicator, duration: 2, options: .TransitionCrossDissolve, animations: { 
     self.logoIndicator.setImage(UIImage(named: "color.png"), forState: .Normal) 
     }, completion: nil) 

    logoIndicator.enabled = true 
} 




} 
0

が最も効果的であるが、そのものではない可能性があります:あなたはこれを使用することができ、この時間後に再び有効ボタンに

let animationDuration = 5.0 
button.imageView.animationImages = [UIImage(named: "image1.png"), UIImage(named: "image2.png")] 
button.imageView.animationDuration = animationDuration 
button.userInteractionEnabled = false 
button.imageView.startAnimating() 

:別の画像からアニメーションする

関連する問題