This is an article of translation. Original source: Http://www.raywenderlich.com/95910/uiview-animation-swift-tutorial
Animation (animation) is a very important knowledge in the iOS user interface. Animation can attract users ' attention and make the program more beautiful and vivid.
More notably, in the flat design era, animation is a key factor in getting good programs off the top.
As an example,
Download this start item (address: Http://cdn4.raywenderlich.com/wp-content/uploads/2015/02/BahamaAir-Starter.zip), the program is a fictitious airline-" Bahama Air "Landing interface. Behind our door is the animation to make this interface more beautiful view.
Now run:
Start implementing a simple animation:
1. Hide the interface
Add the following code in the Viewcontroller.swfit Viewwillappear () method:
Heading.center.x-=-=- = view.bounds.width
Run now, hide three builds, effect
Add the following code in Viewdidappear () to display the header label "Bahama Login"
Uiview.animatewithduration (0.5, animations: { + = Self.view.bounds.width})
After running, the head label "Bahama Login" slides right to the center position,
Delay animation
Add the following code in Viewdidappear () to display the username text input box:
Uiview.animatewithduration (0.50.3, Options:nil, animations: { + = Self.view.bounds.width}, Completion:nil)
Code Explanation:
1.duration: Animation duration
2.delay: Length of delay
3.option: Mask option tells how to show animations, later
4.animation: Closures that show animated content
5.completion: The closure that executes after the animation finishes executing. Use the language cleanup or perform more animations
Post-run effects
UIView properties that can be used to perform animations
Not all UIView properties can be animated, and below we enumerate the UIView properties that can be animated.
1. Positions and sizes (position and size) such as bounds, frame, center
2. Display style (appearance). such as BackgroundColor, Alpha
Deformation (transformation). such as transformation
animation option (Animation options)
1. Repeat repeating
. Repeat: Let animation repeat loop execution
. AutoReverse: can only drink. Use repeat together to let animations run back and forth
2. Animated nature (Animation easing)
Real-life movement does not suddenly start and suddenly stop, but slowly accelerate the start, smooth operation, slow deceleration stop. :
We have four options for animating more naturally (easing) when performing animations:
. Linear: This option makes the animation run smoothly
. Curveeasein: This option lets the animation speed up the start
. Curveeaseout: This option makes the animation slow down
. Curveeaseinout: This option lets the animation speed up and the end of the deceleration.
Add the following code in Viewdidappear ():
Uiview.animatewithduration (0.50.4, |. AutoReverse | . Curveeaseout, animations: { + = Self.view.bounds.width}, Completion:nil)
After running, the Password text box slides in from the left, then decelerates and stops in the middle, the effect
The basic animation is introduced here.
Swift for iOS animation animation tutorial