如何添加Instagram模型'喜欢'动画?

时间:2014-02-10 11:24:56

标签: ios iphone instagram

我正在尝试开发一个显示图像Feed的iPhone应用程序。在应用程序中有喜欢不喜欢的功能。我需要类似于Instagram的效果。

喜欢和喜欢有单独的图像..

我对如何做到这一点很困惑。所以我没有做任何编码。

是否有可用的示例代码?

感谢名单..

1 个答案:

答案 0 :(得分:2)

在你的 - (void)viewDidLoad

UITapGestureRecognizer *oneFingerTwoTaps = 
      [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerTwoTaps)] autorelease];

    // Set required taps and number of touches
    [oneFingerTwoTaps setNumberOfTapsRequired:2];
    [oneFingerTwoTaps setNumberOfTouchesRequired:1];

    // Add the gesture to the view/UIImageView
    [[self view] addGestureRecognizer:oneFingerTwoTaps];

而不是[自我视图]使用您的UIImageView。

在下一步中,您将创建双击图像的操作

- (void)oneFingerTwoTaps
{
  // Action for Fade In the "Heart"
  UIImage *image = [UIImage imageNamed:@"yourlikeimageoverlay.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];


//Add the image view to your main view
//(This is optional if it was created with Interface Builder)
...


CABasicAnimation *theAnimation;

//within the animation we will adjust the "opacity"
//value of the layer
theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
//animation lasts 0.4 seconds
theAnimation.duration=0.4;
//and it repeats forever
theAnimation.repeatCount= 1e100f;
//we want a reverse animation
theAnimation.autoreverses=YES;
//justify the opacity as you like (1=fully visible, 0=unvisible)
theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
theAnimation.toValue=[NSNumber numberWithFloat:0.1];

//Assign the animation to your UIImage layer and the
//animation will start immediately
[imageView.layer addAnimation:theAnimation
                 forKey:@"animateOpacity"];
}