Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tableview scroll is not stopping on tap if i animate tableview cells

I am trying to add animations in tableview cells and the animations are working fine. But when i try to stop the scroll of tableview by tapping its not stopping. Usually in a scrolling tableview if we tap of screen the scroll would stop. But when i add these animations thats not working. below is the code i use for animations

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    let rotationTransform = CATransform3DScale(CATransform3DIdentity, 0.4, 0.4, 0)

    cell.layer.transform = rotationTransform
    UIView.animateWithDuration(0.5) { () -> Void in
        cell.layer.transform = CATransform3DIdentity
    }
}
like image 531
Kalyan Avatar asked Jan 24 '16 18:01

Kalyan


2 Answers

Note:

This is normal behavior for animations using one of the animateWithDuration... method. Still if you want user interaction during the animation you can try like Below i have shown.

Simply you need to try like this :

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    let rotationTransform = CATransform3DScale(CATransform3DIdentity, 0.4, 0.4, 0)
    cell.layer.transform = rotationTransform

    UIView.animateWithDuration(0.5, delay: 0.5, options: UIViewAnimationOptions.AllowUserInteraction, animations: { () -> Void in
        cell.layer.transform = CATransform3DIdentity
        }, completion: nil)
}

Hope it will help to you.

like image 62
Mayur Avatar answered Oct 13 '22 12:10

Mayur


The main thing you’re hitting here is that UIView animations, by default, disable touches on the animating views while an animation is in progress. You can change that behavior by switching to the +animateWithDuration:options:delay:animations:completion: method and adding the UIViewAnimationOptions value AllowUserInteraction, like this:

UIView.animateWithDuration(0.5, delay:0, options:[.AllowUserInteraction], animations:{ () -> Void in
    cell.layer.transform = CATransform3DIdentity
}, completion:nil)
like image 23
Noah Witherspoon Avatar answered Oct 13 '22 11:10

Noah Witherspoon