简体   繁体   中英

UITableViewCell blinks when the height changes

I use Auto Layout cells with automatic height calculation. When I change one of the cell height constraint, call beginUpdates() and endUpdates() for the UITableView , everything is rebuilt correctly, but the animation does not work the way I want — I would like the height of the cell to simply increase, without blinking and moving its upper part. What may it depend on?

I am attaching the GIF with how it is wrong for me to animate now. https://vk.com/doc19187792_491076127

You can write extension to your Cell class and add some animation, and add your cell whenever hit.. Also you should write a completion block to this, when your animation finished, height for row at is called.

This is not your complete solution but you can edit so that your problem may be solved.

extension UIView {

func glow(_ completion: @escaping () -> ()){

    let opacity = CASpringAnimation(keyPath: "opacity")
    let pulse = CASpringAnimation(keyPath: "transform.scale")
    let group = CAAnimationGroup()

    pulse.fromValue = 0.4
    pulse.toValue = 1

    opacity.fromValue = 0
    opacity.toValue = 0.65

    group.animations = [pulse, opacity]
    group.duration = 1.1
    group.timingFunction = CAMediaTimingFunction(name: .easeOut)
    group.autoreverses = false
    group.repeatCount = 0

    layer.add(group, forKey: nil)

    DispatchQueue.main.asyncAfter(deadline: .now()+1) {
        completion()
    }
}
}

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