I am developing a social app in which I want to implement like functionality similar to instagram, there are feeds with images similar to instagram when user double taps any image then it should show a heart icon with animation similar to instagram. I tried to do the same thing but unable to achieve the animation, can anybody tell me how can I do that.
I am attaching the image of instagram like functionality.
Here is an implementation:
- (void) animateLike {
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
heartPopup.transform = CGAffineTransformMakeScale(1.3, 1.3);
heartPopup.alpha = 1.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
heartPopup.transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
heartPopup.transform = CGAffineTransformMakeScale(1.3, 1.3);
heartPopup.alpha = 0.0;
} completion:^(BOOL finished) {
heartPopup.transform = CGAffineTransformMakeScale(1.0, 1.0);
}];
}];
}];
}
Code For Swift 3.0
func likeAnimation() {
UIView.animate(withDuration: 0.3, delay: 0, options: .allowUserInteraction, animations: {() -> Void in
heartPopup.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
heartPopup.alpha = 1.0
}, completion: {(_ finished: Bool) -> Void in
UIView.animate(withDuration: 0.1, delay: 0, options: .allowUserInteraction, animations: {() -> Void in
heartPopup.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
}, completion: {(_ finished: Bool) -> Void in
UIView.animate(withDuration: 0.3, delay: 0, options: .allowUserInteraction, animations: {() -> Void in
heartPopup.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
heartPopup.alpha = 0.0
}, completion: {(_ finished: Bool) -> Void in
heartPopup.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
})
})
})
}
heartPopup
is a UIImageView, set it up in the interface builder in the center of the image and set alpha to zero on it. Call the above method to animate the like effect.
if let bigLikeImageV = likeImageV, liked == true {
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.2, options: .allowUserInteraction, animations: {
bigLikeImageV.transform = CGAffineTransform(scaleX: 1.6, y: 1.6)
bigLikeImageV.alpha = 1.0
}) { finished in
bigLikeImageV.alpha = 0.0
bigLikeImageV.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With