Ios 如何停止tableviewcell按钮上的动画?

Ios 如何停止tableviewcell按钮上的动画?,ios,iphone,swift,animation,audio,Ios,Iphone,Swift,Animation,Audio,我有一个按钮,当我点击它时,它会产生动画,在这个按钮功能中,有一个通知,无论是否播放歌曲,都会生成动画。我想做的是“当我点击它时启动动画,当歌曲播放时停止动画”。我无法停止动画 这是我的密码 func MPMoviePlayerPlaybackStateDidChange(notification: NSNotification){ if (User.postPlayer.playbackState == MPMoviePlaybackState.Playing) { //pl

我有一个按钮,当我点击它时,它会产生动画,在这个按钮功能中,有一个通知,无论是否播放歌曲,都会生成动画。我想做的是“当我点击它时启动动画,当歌曲播放时停止动画”。我无法停止动画

这是我的密码

func MPMoviePlayerPlaybackStateDidChange(notification: NSNotification){

    if (User.postPlayer.playbackState == MPMoviePlaybackState.Playing)
    { //playing

        println("playinggggg")
        buttonsender?.layer.removeAllAnimations()
    }
    else if (User.postPlayer.playbackState == MPMoviePlaybackState.Stopped)
    { //stopped
        println("stopped")
    }else if (User.postPlayer.playbackState == MPMoviePlaybackState.Paused)
    {
        println("paused")
    }else if (User.postPlayer.playbackState == MPMoviePlaybackState.Interrupted)
    {
        println("interupted")
    }else if (User.postPlayer.playbackState == MPMoviePlaybackState.SeekingForward)
    {
        println("skip forward")
    }else if (User.postPlayer.playbackState == MPMoviePlaybackState.SeekingBackward)
    {
        println("skip before")
    }

}


func playPost(sender: UIButton){

    NSNotificationCenter.defaultCenter().addObserver(self,

        selector: "MPMoviePlayerPlaybackStateDidChange:",

        name: MPMoviePlayerPlaybackStateDidChangeNotification,

        object: nil)

    animateButton(sender)

    User.postPlayer.stop()
    var songUrl = sender.layer.valueForKey("songUrl") as? String
    println(songUrl)

    clickedIndex = sender.layer.valueForKey("index") as? Int
    sender.setTitle("II", forState: UIControlState.Normal)
    User.postPlayer.contentURL = NSURL(string: songUrl!)
    User.postPlayer.play()

    buttonsender = sender

}

func animateButton(sender: UIButton) {
    let defaultDuration = 2.0
    let defaultDamping = 0.20
    let defaultVelocity = 6.0

    sender.transform = CGAffineTransformMakeScale(0.1, 0.1)

    UIView.animateWithDuration(defaultDuration,
        delay: 0,
        usingSpringWithDamping: CGFloat(defaultDamping),
        initialSpringVelocity: CGFloat(defaultVelocity),
        options: UIViewAnimationOptions.AllowUserInteraction,
        animations: {
            sender.transform = CGAffineTransformIdentity
        },
        completion: { finished in
            self.animateButton(sender)
        }
    )
}
buttonsender是一个全局变量。 播放歌曲时如何停止动画?
或者,如果有人对加载有更好的解决方案,我会尝试查看,只要给出任何建议。用objective c或swift编写都无所谓。

试试这个,它应该会停止

[CATransaction begin];
[theView.layer removeAllAnimations];
[CATransaction commit];

大家好,我们用微笑的方式播放并停止了按钮的启用和禁用。当播放歌曲时,我们禁用播放按钮并启用停止按钮。我只使用了一个按钮。是的,一个按钮我们可以播放/停止。按钮名称相应地,无论是播放模式还是停止模式,我们都可以通过编程方式更改。如何更改按钮名称?创建一个带有标签的按钮,并使其成为条件。(if and else)如果tag=0使播放模式else停止模式,则在条件内给出按钮标题。