简体   繁体   中英

TableView animation when the cell is tapped

I would like to animate the tableView cell when the user put is finger on it like in this image 在此处输入图片说明

and when the user stop pressing, the cell come back in the original size (my tableView is not using a custom cell but the default UItableViewCell). I looked around the net to find some tutorial or something useful but nothing, someone can tell me how can i do?

You can do it like this:

On Touch Down Event for UITableViewCell:

UIView.animateWithDuration(0.2, delay: 0.1, usingSpringWithDamping: 0.9, initialSpringVelocity: 5, options: [],animations: {
            self.contentView.transform = CGAffineTransformMakeScale(0.95, 0.95)
            }, completion: { finished in

        })

And On Touch Up Event for UITableViewCell:

UIView.animateWithDuration(0.2, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 5, options: .CurveEaseIn,animations: {
            self.contentView.transform = CGAffineTransformMakeScale(1, 1)
            },completion: { finished in

        })

Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM