swift2.0学习笔记之实现图片变圆

来源:互联网 发布:如何做淘宝兼职 编辑:程序博客网 时间:2024/05/16 06:07

用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.将图片继承这个类



0 0