用swift开发音乐播放器时,有时为了图片的炫酷化,将图片变为圆形,并且旋转。
使用方法如下
1.自定义一个UIimageView
import UIKit
class myimage: UIImageView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//允许圆角化
self.clipsToBounds=true
//圆角半径
self.layer.cornerRadius=self.frame.size.width/2.0
self.layer.borderWidth=4.0
self.layer.borderColor=UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7).CGColor
}
//旋转
func onRoation()
{
let animation=CABasicAnimation(keyPath: "transform.rotation")
animation.fromValue=0.0
animation.toValue=M_PI*2.0
animation.duration=20.0
animation.repeatCount=10000
self.layer.addAnimation(animation, forKey: nil)
}
}
2.将图片继承这个类
本文介绍如何使用Swift开发音乐播放器时,将图片变为圆形并实现旋转效果,通过自定义UIimageView类,实现圆角化、设置颜色边框及旋转动画。
1041

被折叠的 条评论
为什么被折叠?



