Instagram“喜欢”动画iOS

时间:2012-09-11 05:16:04

标签: iphone ios xcode ios5

我希望实现Instagram在您将图片双击到我的iOS应用程序时使用的“喜欢”动画。这是一个非常漂亮的功能,并认为它会为我的应用程序添加一点味道。我发布了双击之前和之后的照片。心脏在大约两秒钟内消失。我想不明白。让我知道!

Before

After

3 个答案:

答案 0 :(得分:0)

如果你想使用动画方法,你可以使用framesequance来做到这一点。

Toast(因为它在android中)aproach也很完美,为此你可以在这里检查一个重复的问题Growl/toast style notifications library for iOS

答案 1 :(得分:0)

#define LIKED 100 //change as per your requirement
#define UNLIKE 200 //change as per your requirement

- (void) likeUnlike:(UIGestureRecognizer *)sender
{
    [imageViewSub setHidden:NO];

    UIImageView *imageView = (UIImageView *)sender.view;

    if(imageView.tag==LIKED)
    {
        [imageViewSub setImage:[UIImage imageNamed:@"unlike.png"]];
        [imageView setTag:UNLIKE];
    }
    else
    {
        [imageViewSub setImage:[UIImage imageNamed:@"like.png"]];
        [imageView setTag:LIKED];
    }

    //here, your like/unlike update call to server for store selection.

    //set the frame exactly you want or
    //implement some other way to hide `imageViewSub` after like/unlike
    [imageViewSub setFrame:CGRectMake( 110, 180, 100, 100)];
    [UIView beginAnimations:@"anim" context:nil];
    [UIView setAnimationDuration:1.0];
    [imageViewSub setFrame:CGRectMake(200, 200, 0, 0)]; 
    [UIView commitAnimations];
}

//Add below code where you're added/showing your images. There's always two `UIImageView`s one is `main` and other one is `sub`.

[imageViewSub bringSubviewToFront:imageViewMain];

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] init];
[doubleTap setNumberOfTapsRequired:2];
[doubleTap addTarget:self action:@selector(likeUnlike:)];
[imageViewMain addGestureRecognizer:doubleTap];
[doubleTap release];

P.S。 imageViewMain最初会有来自UNLIKEDimageViewSub unlike.png的标记,并且应该被隐藏。

答案 2 :(得分:0)

在我的一些项目中,我一直在使用MBProgressHUD。您可以设置标准图像/进度圆或自定义图像,也可以自定义标签的字体。我非常喜欢它。如果您将它与performBlockAfterDelay (check this category)一起使用,它可以为您节省大量时间并让您的生活更轻松。