Example code for easy animation on UItTablViewCell.
I’m use willDisplayCell Function and insert animation to cell
1 2 3 4 5 6 7 8 9 10 11 12 13 |
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { cell.frame = CGRectMake(scRect.width, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height) UIView.animateWithDuration(1.0, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.6, options: UIViewAnimationOptions.CurveEaseIn, animations: { cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height) }, completion: { finished in }) } |
This amazing function added for iOS 7.
I read reference from apple doc >> Link << and i will summary about new parameter on this function.
1 2 3 4 5 6 7 |
[UIView animateWithDuration:(CGFloat)duration delay:(CGFloat)delay usingSpringWithDamping:(CGFloat)damping initialSpringVelocity:(CGFloat)velocity options:(UIviewAnimationOptions)options animations:^() (animations) completion:^(BOOL finished) (completion)] |
Parameter
[tabs][tab title=”duration”] The total duration of the animations, measured in seconds. [/tab] [tab title=”delay”] The time in seconds to wait before beginning the animations. If you don’t need delay can set to 0 for begin the animations immediately. [/tab] [tab title=”damping”] You can set value 0 to 1. To smoothly decelerate the animation without oscillation, use a value of 1. Employ a damping ratio closer to zero to increase oscillation. [/tab][tab title=”velocity”] The initial spring velocity. For smooth start to the animation, match this value to the view’s velocity as it was prior to attachment.
A value of 1 corresponds to the total animation distance traversed in one second. For example, if the total animation distance is 200 points and you want the start of the animation to match a view velocity of 100 pt/s, use a value of 0.5.[/tab][/tabs]
Download example code : link
Thank nice image from
http://littlevisuals.co/