实现图片抛物线的效果
来源:互联网 发布:网络出版企业 编辑:程序博客网 时间:2024/06/10 09:05
实现图片抛物线的效果
最近做项目,需要实现图片抛物线效果,研究了下,方法有二;
方法一:
-(void)isButtonClicked:(id)sender
{
CGRect rect = [self.viewconvertRect:((UIButton *)sender).boundsfromView:sender];
UIImageView *imageView = [[[UIImageViewalloc] initWithFrame:CGRectMake(0,10, 30, 30)]autorelease];
imageView.frame =CGRectMake(rect.origin.x+10, rect.origin.y,30, 30);
[self.viewaddSubview:imageView];
imageView.image = [UIImageimageNamed:@"forward.png"];
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];
CGMutablePathRef thePath =CGPathCreateMutable();
CGPathMoveToPoint(thePath, NULL, imageView.frame.origin.x, imageView.frame.origin.y);
CGPathAddQuadCurveToPoint(thePath,NULL, 220, 30,230, 440);
bounceAnimation.duration =1.0f;
bounceAnimation.path = thePath;
bounceAnimation.delegate =self;
[bounceAnimationsetValue:imageView forKey:@"image"];
[imageView.layeraddAnimation:bounceAnimation forKey:@"move"];
CGPathRelease(thePath);
imageView.layer.position =CGPointMake(1000,300);
}
方法二:
-(void)TransAnimation:(UIImage *)image
{
#define PI3.14159265
CGRect headImageOrgRect = headImageView.frame;
CGSize size = image.size;
CGFloat midX = headImageView.center.x;
CGFloat midY = headImageView.center.y;
[headImageView setFrame:CGRectMake(0,0, size.width, size.height)];
CALayer *TransLayer = headImageView.layer;
// Create a keyframe animation to follow a path back to the center
CAKeyframeAnimation *animation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];
animation.removedOnCompletion =NO;
CGFloat animationDuration =0.3;
// Create the path for the bounces
CGMutablePathRef thePath =CGPathCreateMutable();
CGFloat originalOffsetX = headImageView.center.x - midX;
CGFloat originalOffsetY = headImageView.center.y - midY;
BOOL stopAnimation =NO;
CGPathMoveToPoint(thePath,NULL, headImageView.center.x, headImageView.center.y);
float xPosition ;
float yPosition ;
float angle =0.0f;
while (stopAnimation !=YES) {
xPosition = headImageView.center.x - originalOffsetX*sin(angle*(PI/180));
yPosition = headImageView.center.y - originalOffsetY*sin(angle*(PI/180));
CGPathAddLineToPoint(thePath,NULL, xPosition, yPosition);
angle = angle +1.0f;
if(angle ==90.0f||angle >90.0f)
stopAnimation =YES;
}
[headImageView setCenter:CGPointMake(midX,midY)];
animation.path = thePath;
CGPathRelease(thePath);
animation.duration = animationDuration;
// Create a basic animation
CABasicAnimation *shrinkAnimation = [CABasicAnimationanimationWithKeyPath:@"bounds"];
shrinkAnimation.removedOnCompletion =YES;
shrinkAnimation.duration = animationDuration;
shrinkAnimation.fromValue = [NSValue valueWithCGRect:headImageView.frame];
shrinkAnimation.byValue = [NSValuevalueWithCATransform3D:CATransform3DIdentity];
shrinkAnimation.toValue = [NSValuevalueWithCGRect:headImageOrgRect];
// Create an animation group to combine the keyframe and basic animations
CAAnimationGroup *theGroup = [CAAnimationGroupanimation];
// Set self as the delegate to allow for a callback to reenable user interaction
theGroup.delegate =self;
theGroup.duration = animationDuration;
theGroup.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];
theGroup.animations = [NSArrayarrayWithObjects:animation, shrinkAnimation,nil];
// Add the animation group to the layer
[TransLayeraddAnimation:theGroupforKey:@"animatePlacardViewToCenter"];
// Set the view's center and transformation to the original values in preparation for the end of the animation
headImageView.transform = CGAffineTransformIdentity;
[headImageView setFrame:headImageOrgRect];
}
- 实现图片抛物线的效果
- 实现图片抛物线的效果
- JavaScript实现的抛物线运动效果
- 王学岗的属性动画上(五)------抛物线效果的实现
- 加入购物车抛物线效果的基本实现(一)
- 实现购物车点击添加的抛物线动画效果
- Android ImageView 图片抛物线动画的实现方案
- cocos2d 抛物线的实现
- 抛物线拟合算法的实现
- 控件抛物线轨迹的实现
- 使用自定义+属性动画实现小圆球抛物线的效果
- React、Vue实现购物车小球抛物线效果
- Unity中物体抛物线的实现方式
- Unity中物体抛物线的实现
- Unity中物体抛物线的实现方式
- unity 抛物线 效果演示
- 图片阴影效果的实现
- 图片阴影效果的实现
- DLL动态链接库的工作原理
- SilverLight 4页面跳转大全
- 职责链模式
- dpkg 查询
- MIME_type类型语法
- 实现图片抛物线的效果
- 网络编程基础
- Delphi异常机制与SEH
- Mysql Cache配置使用 mysql缓存配置
- 思科2900交换机vlan设置
- gbd常用命令
- 有对 skypekit 感兴趣的同学吗?
- Android APK反编译详解(附图) .
- Navigation(多页面切换、传值)