繁体   English   中英

Instagram“喜欢”动画iOS

[英]Instagram “like” animation iOS

我要实现在将图片双击到我的iOS应用中时Instagram使用的“喜欢”动画。 这是一个非常漂亮的功能,并认为它将为我的应用程序增添些许风味。 我张贴了双击的前后照片。 心脏在大约两秒钟内消失。 我想不明白。 让我知道!

之前

后

好吧,如果您想使用动画方法,则可以使用帧序列进行此操作。

Toast(因为它在android中)也很完美,为此,您可以在此处检查iOS的重复问题Growl / toast样式通知库

#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];

PS imageViewMain最初将具有标签UNLIKEDimageViewSubunlike.png和应该被隐藏。

在我的一些项目中,我一直在使用MBProgressHUD 您可以设置标准图像/进度圈或自定义图像,还可以自定义标签的字体。 我很喜欢 如果将它与performBlockAfterDelay一起使用(选中此类别) ,则可以节省大量时间,并使您的生活更轻松。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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