如何在 ios 中为附件制作类似 whatsapp 的动画?
How to do whatsapp like animation for attachment in ios?
我正在尝试实现类似于 whatsapp 附件的动画。我的意思是当我们点击附件按钮时的视图动画。知道怎么做吗?
您可以使用所需的多个 UIButton
添加自定义 UIView
,然后您可以根据需要显示或隐藏 UIView
。
在附件按钮的动作上,添加如下代码,动画已经设置好。
- (IBAction)onbtnTapped:(id)sender {
self.view1.frame = CGRectMake( _btn1.frame.origin.x+_btn1.frame.size.width, _btn1.frame.origin.y+_btn1.frame.size.height, 0, 0);
self.view1.hidden=NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.5];
[UIView setAnimationDelegate: self];
self.view1.transform = CGAffineTransformMakeTranslation( 1, 1);
self.view1.frame = CGRectMake( 0, 50, self.view.frame.size.width, 200);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = [NSNumber numberWithFloat: 100];
animation.toValue = [NSNumber numberWithFloat: 0];
animation.duration = 0.5;
[self.view1.layer setCornerRadius: 0];
[self.view1.layer addAnimation:animation forKey:@"cornerRadius"];
[UIView commitAnimations];
}
我正在尝试实现类似于 whatsapp 附件的动画。我的意思是当我们点击附件按钮时的视图动画。知道怎么做吗?
您可以使用所需的多个 UIButton
添加自定义 UIView
,然后您可以根据需要显示或隐藏 UIView
。
在附件按钮的动作上,添加如下代码,动画已经设置好。
- (IBAction)onbtnTapped:(id)sender {
self.view1.frame = CGRectMake( _btn1.frame.origin.x+_btn1.frame.size.width, _btn1.frame.origin.y+_btn1.frame.size.height, 0, 0);
self.view1.hidden=NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.5];
[UIView setAnimationDelegate: self];
self.view1.transform = CGAffineTransformMakeTranslation( 1, 1);
self.view1.frame = CGRectMake( 0, 50, self.view.frame.size.width, 200);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = [NSNumber numberWithFloat: 100];
animation.toValue = [NSNumber numberWithFloat: 0];
animation.duration = 0.5;
[self.view1.layer setCornerRadius: 0];
[self.view1.layer addAnimation:animation forKey:@"cornerRadius"];
[UIView commitAnimations];
}