如何在按钮周围应用动画? [英] How do I apply an animation around a button?

查看:62
本文介绍了如何在按钮周围应用动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当播放按钮播放时,我正在播放30秒的歌曲.我希望进度条在播放歌曲时围绕播放按钮.我该怎么做?

I have 30 sec of a song being played when the play button is being played. I want a progress bar to go around the play button as the song is being played. How would I do this?

play = add[indexPath.row]
    let playButton : UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
    playButton.tag = indexPath.row
    let imageret = "playbutton"
    playButton.setImage(UIImage(named: imageret), forState: .Normal)
    playButton.frame = CGRectMake(236, 20, 100, 100)
    playButton.addTarget(self,action: "playit:", forControlEvents: UIControlEvents.TouchUpInside)

推荐答案

我假设您想要这样的东西:

I'm assuming you want something like this:

这是一个CAShapeLayer,其路径是一个圆.我们以strokeEnd为0并为其设置最大1的动画.您可以使用NSTimer以1秒的间隔来轮询歌曲的进度,并计算歌曲的播放量,然后将strokeEnd设置为那部分.

It is a CAShapeLayer whose path is a circle. We start with a strokeEnd of 0 and animate it up to 1. You can poll the song's progress using an NSTimer at, say, 1-second intervals and calculate how much of the song has played, and set the strokeEnd to that fraction.

这篇关于如何在按钮周围应用动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆