iOS Animations

1. Spring Animations (弹性动画)

 animateWithDuration(_:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:) 

• usingSpringWithDamping: This controls the amount of damping, or reduction,applied to the animation as it approaches its final state. This parameter accepts values between0.0and1.0. Values closer to0.0create a bouncier animation,while values closer to1.0create a stiff-looking effect. You can think of this value as the “stiffness” of the spring.

• initialSpringVelocity: This controls the initial velocity of the animation. A value of 1.0sets the velocity of the animation to cover the total distance of the animation in the span of one second. Bigger values will cause the animation to have more velocity, because it has more momentum at the beginning of its movement and takes longer to settle down into its final position. 

The spring behavior affects all properties you animate.

2. Transitions Animations(过渡动画)

Transitions are predefined animations you can apply to views. You’ll design the animations so that the various changes in state appear natural.

There are the various animation scenarios where you could make use of transition animations. 

  • Adding a new view (Container view to be its superview)
  • Removing a view (Container view to be its superview)
  • Showing / Hiding a view (Container view to be the view itself)
  • Replacing a view with another view

Transitions are a small but important subset of animation knowledge to keep in your figurative toolbox since they’re the only way to create 3D-styled animations inUIKit. 

Transitions can be used to animate changes to non-animatable properties of your views. 

3. Keyframe Animations(帧动画)

When it comes to multiple, sequential animations for your views, you'd better use keyframe animations. Keyframes are an incredibly useful and flexible way to design and control your animations. 

You can split the total animation into four distinct stages, or keyframes,and then combine the individual keyframes into a keyframe animation

Use animateKeyframesWithDuration(_:delay:options:animations:completion:) to create keyframe animation, then use

addKeyframeWithRelativeStartTime(_:relativeDuration:animations:) to add key frames into its animations closure.  

The two time parameters of  addKeyframeWithRelativeStartTime(_:relativeDuration:animations:) both should be in the range 0 to 1.They are like percentage of the duration of the whole animation.

Keyframe animations don’t support the built-in easing curves that are available in standard UIView animations. This is by design: keyframes are supposed to start and end at specific times and flow into each other.

If each stage of your animation above had an easing curve, the plane would jerk around instead of moving smoothly from one animation into the next. If you could apply easing to the entire animation, that would result in your animation durations being ignored – and that’s not what you want. 

Instead, you have several calculation modes to choose from; each mode offers a different method to calculate intermediate frames of the animation as well as different optimizers for smooth movement and even pacing. Check out the documentation by searching for UIViewKeyframeAnimationOptions for more details. 


4. Animate Constraints

In order for Auto Layout to work properly, you can’t fiddle directly with the view’s frame or center properties; instead, you can work with the layout constraints to create your desired animations. 

Basically, there are two possible cases:

1).  you only need to change the constant in the constraint’s equation
2). you simply replace an existing constraint with a new one 

Animating constraints is no more difficult than animating properties – just remember to call layoutIfNeeded in the animation closure to refresh the layout and make the animation.

Note: If you’ve used Auto Layout from code before you might be accustomed to a method called addConstraint on UIView to add your constraints.

In iOS 8, the preferred approach now is to add constraints by setting theiractive property or calling NSLayoutConstraint.activateConstraints(_:) withan array to activate many constraints at once. 

 





  






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值