Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS如何创建类似于Twitter心脏按钮的动画按钮?_Ios_Objective C_Animation_Uiview_Uibutton - Fatal编程技术网

iOS如何创建类似于Twitter心脏按钮的动画按钮?

iOS如何创建类似于Twitter心脏按钮的动画按钮?,ios,objective-c,animation,uiview,uibutton,Ios,Objective C,Animation,Uiview,Uibutton,在过去,我创建了自定义按钮并使用自定义UIView。然而,我不知道该怎么做 我正在尝试创建类似于twitter心脏动画的东西。 我无法得到的是这些环绕心脏的微小彩色圆圈,如图所示: 有什么想法吗 另外,我是否可以简单地使用gif并将gif作为自定义视图添加到UIButton中,并在按下按钮时播放gif?以下是一个概念: -(无效)视图显示:(BOOL)动画{ [超级视图显示:动画]; UIView*bubble=[[UIView alloc]initWithFrame:CGRectMake(

在过去,我创建了自定义按钮并使用自定义UIView。然而,我不知道该怎么做

我正在尝试创建类似于twitter心脏动画的东西。 我无法得到的是这些环绕心脏的微小彩色圆圈,如图所示:

有什么想法吗

另外,我是否可以简单地使用gif并将gif作为自定义视图添加到UIButton中,并在按下按钮时播放gif?

以下是一个概念:


-(无效)视图显示:(BOOL)动画{

[超级视图显示:动画]; UIView*bubble=[[UIView alloc]initWithFrame:CGRectMake(0.0,0.0,16.0,16.0)]; bubble.layer.cornerRadius=8.0; bubble.center=self.view.center; bubble.backgroundColor=[UIColor greenColor]; [self.view addSubview:bubble]; UIView*heart=[[UIView alloc]initWithFrame:CGRectMake(0.0,0.01000.01000.0)]; heart.layer.cornerRadius=50.0; heart.center=self.view.center; heart.backgroundColor=[UIColor blueColor]; [self.view addSubview:heart]; [UIView animateKeyframesWithDuration:2.0 延迟:0.0 选项:UIViewKeyframeAnimationOptionRepeat 动画:^{ //心膨胀 [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.10动画:^{ heart.transform=CGAffineTransformMakeScale(1.3,1.3); }]; //心脏收缩。 [UIView addKeyframeWithRelativeStartTime:0.15 relativeDuration:0.25动画:^{ heart.transform=CGAffineTransformMakeScale(1.0,1.0); }]; //泡泡旅行。 [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.4动画:^{ CGPoint destination=self.view.center; 目的地x+=100; 目的地y-=100; bubble.center=目的地; }]; //泡沫缩小了。 [UIView addKeyframeWithRelativeStartTime:0.6 relativeDuration:0.2动画:^{ bubble.transform=CGAffineTransformMakeScale(0.3,0.3); }]; //泡沫消退。 [UIView addKeyframeWithRelativeStartTime:0.8 RelativeEduation:0.2动画:^{ 气泡α=0.0; }]; }完成:无]; }

要获得完整的效果,您需要再添加几个关键帧,以便气泡在淡入淡出之前弯曲。如果您有两个气泡,创建关键帧生成器可能是一个好主意。

或者,您可以使用SKEmitterNode并将真实粒子添加到按钮中

回答晚,但对其他开发人员有用。 以下是完全相同动画的链接:


Objective-C中的动画也一样:

animateKeyFramesWithDuration可能会让你获得90%的效果。@谢谢,你知道如何创建气泡吗?可能使用一个16×16大小和层的UIView。cornerRadius设置为8。@ncke所以我将为每个气泡创建一个圆形UIView,并为外部的运动设置动画?是的。只是个主意。气泡将是心脏的子视图,你可以做运动停止淡入淡出的事情作为关键帧。非常感谢!我将在几天后尝试并更新它。Shi Mitul,你知道如何在Objective C中使用动画吗?我对如何将favicon添加到我的VC有点困惑。没有点击功能为我添加代码,我甚至不知道如何把它在导航栏,请帮助。

- (void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated]; UIView *bubble = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 16.0, 16.0)]; bubble.layer.cornerRadius = 8.0; bubble.center = self.view.center; bubble.backgroundColor = [UIColor greenColor]; [self.view addSubview:bubble]; UIView *heart = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)]; heart.layer.cornerRadius = 50.0; heart.center = self.view.center; heart.backgroundColor = [UIColor blueColor]; [self.view addSubview:heart]; [UIView animateKeyframesWithDuration:2.0 delay:0.0 options:UIViewKeyframeAnimationOptionRepeat animations:^{ // Heart expands [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.10 animations:^{ heart.transform = CGAffineTransformMakeScale(1.3, 1.3); }]; // Heart contracts. [UIView addKeyframeWithRelativeStartTime:0.15 relativeDuration:0.25 animations:^{ heart.transform = CGAffineTransformMakeScale(1.0, 1.0); }]; // Bubble travels. [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.4 animations:^{ CGPoint destination = self.view.center; destination.x += 100; destination.y -= 100; bubble.center = destination; }]; // Bubble shrinks. [UIView addKeyframeWithRelativeStartTime:0.6 relativeDuration:0.2 animations:^{ bubble.transform = CGAffineTransformMakeScale(0.3, 0.3); }]; // Bubble fades. [UIView addKeyframeWithRelativeStartTime:0.8 relativeDuration:0.2 animations:^{ bubble.alpha = 0.0; }]; } completion:nil]; }