Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement instagram similar like effect in ios? [closed]

Tags:

ios

instagram

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.
enter image description here

like image 300
rahul Avatar asked Dec 01 '22 02:12

rahul


1 Answers

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.

Swift 4 (code from comment)

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)
        }
}
like image 193
krisrak Avatar answered Dec 06 '22 01:12

krisrak