Swift-calayer Animation of Contents properties

Source: Internet
Author: User
Tags uikit

Swift-calayer Animation of Contents properties

Effect

Source

Https://github.com/YouXianMing/Swift-Animations

////Liveimageview.swift//swift-animations////Created by youxianming on 16/8/17.//copyright©2016 year youxianming. All rights reserved.//Import UIKit//mark:public Class:liveimageviewclassLiveimageview:uiimageview {//mark:properties.        ///Animation ' s duration.var duration:cftimeinterval =0.3        //Mark:methods.        /** Set image with animation or not.     -Parameter newval:the new image.     -Parameter animated:animated or not. */func setimage (newval:uiimage, animated:bool) {ifAnimated = =true{Let animation= Cabasicanimation (keypath:"Contents") Animation.fromvalue= image?. Cgimage Animation.tovalue=newval.cgimage animation.duration=Duration player.contents= image?. Cgimage player.addanimation (animation, forkey:nil) image=newval}Else{image=newval}} //mark:private Value & func.        Privatevar player:calayer!OverrideInit (frame:cgrect) {super.init (frame:frame) PLayer=Layer} required init?(coder Adecoder:nscoder) {fatalerror ("Init (coder:) has not been implemented")    }}
////Liveimageviewcontroller.swift//swift-animations////Created by youxianming on 16/8/17.//copyright©2016 year youxianming. All rights reserved.//Import UIKitclassLiveimageviewcontroller:normaltitleviewcontroller {var timer:gcdtimer! =Gcdtimer (InQueue:GCDQueue.mainQueue) var count:nsinteger! =0var images: [UIImage]! =[UIImage] ()Overridefunc Setup () {Super.setup () images=[UIImage] () images.append (UIImage (named:"pic_1")!) Images.append (UIImage (named:"pic_2")!) Images.append (UIImage (named:"Pic_3")!) Images.append (UIImage (named:"Pic_4")!) Let image= images[0] Let Liveimageview= Liveimageview (Frame:cgrectmake (0,0, Image.size.width, Image.size.height)) Liveimageview.center= (Contentview?. Middlepoint)!LiveImageView.layer.borderWidth=3LiveImageView.layer.borderColor=Uicolor.blackcolor (). Cgcolor liveimageview.duration=0.5Contentview?. Addsubview (Liveimageview) weak var wself=Self timer.Event({Let currentindex= (wself?. Count)! % (wself?. Images.count)!wself?. Count = (wself?. Count)! +1Liveimageview.setimage (wself!. Images[currentindex], animated:true) uiview.animatewithduration (0.5, animations: {var tmprect=liveimageview.bounds tmprect.size= (liveimageview.image?. Size)!Liveimageview.bounds=Tmprect Liveimageview.center= (wself?. Contentview?. Middlepoint)!})}, Timeintervalwithseconds:1.0) Timer.start ()}}

Swift-calayer Animation of Contents properties

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.