2015-11-16 49 views
0

我用UIButton通過某些圖像製作了一個動畫。 下面的代碼:如何停止我的UIButton動畫SWIFT

  @IBAction func Touchdown(sender: AnyObject) { 
    Izer.setImage(image1, forState: UIControlState.Normal) 
    Izer.imageView!.animationImages = [image1, image2, image3, image4,     image5, 
     image6, image7,image8] 
    Izer.imageView!.animationDuration = 0.9 
    Izer.imageView!.startAnimating() 
      playButton.enabled = false 



} 





@IBAction func TouchUp(sender: AnyObject) { 

    soundRecorder.stop() 
    playButton.enabled = true 


} 

當我觸摸按鈕,動畫的開始。但我想通過我的Touchup功能來阻止它。

我該怎麼辦?

謝謝和抱歉,我的英語不好:(

+0

您是否嘗試過在您的TouchUp方法中放入'Izer.imageView!.stopAnimating()'? –

+0

@ Phoen1xUK Owwww男人謝謝你! – Moussdog

+0

只是要添加此作爲答案,所以我們可以關閉該問題:) –

回答

2

添加到您的TouchUp FUNC:

Izer.imageView!.stopAnimating() 

附:在Apple文檔中找到有關函數信息的好地方 - 它確實非常好。所以this is the page for an imageView,如果你在任務的左邊看,或者如果你向下滾動,你可以看到你可以調用和設置爲動畫imageView的函數和屬性。

1

好吧,看起來像你想要的按鈕作爲一個切換開關。在第一次觸摸按鈕開始動畫效果的ImageView和記錄的東西。當感動再次啓動動畫並且再次啓用按鈕

您可以通過聲明一個跟蹤按鈕狀態的bool變量來實現此目的,如果布爾值設置爲true,則運行動畫&錄製。布爾值爲false,您停止並錄製。

這裏是示例代碼:

class ViewController: UIViewController { 

@IBOutlet weak var mainView: UIView! 
var isButtonPressed = false{ 
    // Adding a Property Observer, that reacts to changes in button state 
    didSet{ 
     if isButtonPressed{ 
      // Run the Recording function & Animation Function. 
      startAnimationAndRecording() 
     }else{ 
      // Stop the Recoding function & Animation Function. 
      stopAnimationAndRecording() 
     } 
    } 
} 

@IBAction func changeButtonValue(sender: UIButton) { 
    // Toggle the button value. 
    isButtonPressed = !isButtonPressed 
} 

func startAnimationAndRecording(){ 
    // Add your animation and recording code here. 
} 

func stopAnimationAndRecording(){ 
    //Add your stop Animation & Stop Recording code here. 
} 

}

+0

嘿謝謝你的信息!但我不知道要放什麼代碼停止動畫... – Moussdog