Swift version imitation NetEase cloud music play Music animation effect

Source: Internet
Author: User

Welcome to the Personal Technology blog station


Create a view that inherits from UIView we call him Xtactivityview.

        /// 立方柱的个数    var0;        /// 立方柱的颜色    var rectBackgroundColor: UIColor?        /// 立方柱初始化大小    var defaultSize: CGSize?        /// 立方柱之间的间距    var0.0

To initialize

CGRect) {        super.init(frame: frame)        self.createDefaultAttribute(frame)    }
CGRect) -> Void {        6;        self.rectBackgroundColorUIColor.blackColor()        1;        defaultSize = frame.size    }

Provides start and end interfaces (that is, create and remove)

func startAnimation() {        self.addRect()    }func stopAnimation() {        self.removeRect()    }

Add a rectangle

Func addrect (), Void {self. Removerect() Self. Hidden= False For Iinch 0... Numberofrect{Letx= (cgfloat) (i) * (5+ space) Let Rview = UIView. Init(Frame:cgrectmake (x,0,5, defaultsize!. Height)) Rview. BackgroundColor= Rectbackgroundcolor Rview. Layer. Addanimation(Self. Addanimatewithdelay((Double) (i) *0.2), Forkey:"Tbrotate") Self. Addsubview(Rview)} }

Animation effects

Func Addanimatewithdelay (delay:double), caanimation {Let animation = Cabasicanimation. Init(KeyPath:"Transform.rotation.x") animation. RepeatCount= Maxfloat;Animation. Removedoncompletion= True;Animation. Autoreverses= False;Animation. Timingfunction= Camediatimingfunction. Init(name:kcamediatimingfunctionlinear) Animation. Fromvalue= NSNumber. Init(Float:0) animation. Tovalue= NSNumber. Init(DOUBLE:M_PI) Animation. Duration= (Double) (numberofrect) *0.2;Animation. BeginTime= Cacurrentmediatime () + delay;return animation;}

Remove Rectangle

-> Void {        ifself.subviews.>0 {            self.removeFromSuperview()        }        self.=true    }

Called in the Controller

self.view.backgroundColor = UIColor.whiteColor()let xt = XTActivityView.init(frame: CGRectMake(0108015))xt.startAnimation()self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(customView: xt)xt.performSelector(Selector("stopAnimation"5)

Everyone, I'm the demo address.
Welcome to the Personal Technology blog station

Swift version imitation NetEase cloud music play Music animation effect

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.