Many properties of animation, such as location, transparency, etc., can be used by developers to customize the animation they need. Now let's simply implement how to customize the animation, taking the change of view transparency as an example. Other animation effects can refer to my other two blog "iOS Project development Combat-View animation effect" "iOS project development Combat-implementation of view switch animation."
(1) Also drag a picture into the images.xcassets, and then use a ImageView control in the Main.storyboard to include the image. and bind the control to the code.
(2) Then implement the code below in Viewcontroller, I simply realized the effect of the transparency loop change:
Import Uikitclass Viewcontroller:uiviewcontroller {@IBOutlet weak var image:uiimageview! var Isalpha1:bool = True override func Viewdidload () {super.viewdidload () Self.view.addSubview (i Mage)} override func didreceivememorywarning () {super.didreceivememorywarning ()//Dispose O F any resources the can be recreated. } override func Touchesbegan (touches:set<nsobject>, Withevent event:uievent) {func anim1 () { Image.alpha = 0.5//translucent;} func anim2 () {image . Alpha = 1.0//opaque;} func complete (v:bool) {println (' complete ') is ALPHA1 =!ISALPHA1//cycle changes transparency;} if (ISALPHA1) {Uiview.transitionwithview (Image, duration:1.0, Options:UIViewAnimationOptions.TransitionNone, ANIMATIONS:ANIM1, Completion:complete) }else{Uiview.transitionwithview (image, duration:1.0, Options:UIViewAnimationOptions.TransitionNone, animation S:ANIM2, Completion:complete)}}}
(3) The result of the final implementation is as follows:
。
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS project development Combat-Configure custom animations