iOS 7 动画UIDynamicAnimator

本文介绍了一种在iOS应用中实现重力动画的方法。通过使用UIDynamicAnimator, UIGravityBehavior和UIAttachmentBehavior等组件,文章详细展示了如何创建并设置动画效果,包括重力行为的配置及对象间的连接特性。
- (void)viewDidLoad
{
    [super viewDidLoad]; 
    [self initUI];
    [self performSelector:@selector(startGravity:) withObject:Nil afterDelay:1];// Do any additional setup after loading the view, typically from a nib.
}

// 开始重力行为
- (IBAction)startGravity:(id)sender
{
 //  设为全局才会有效,不知什么原因 animator
= [[UIDynamicAnimator alloc] initWithReferenceView:self.view];//动画方法都根据这个调用 UIGravityBehavior* gravityBeahvior = [[UIGravityBehavior alloc] initWithItems:@[HUDView]]; [animator addBehavior:gravityBeahvior]; UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:HUDView attachedToAnchor:CGPointMake(100, 0)]; [attachmentBehavior setLength:200]; [attachmentBehavior setDamping:0.1]; [attachmentBehavior setFrequency:5]; [animator addBehavior:attachmentBehavior]; } -(void)initUI{ HUDView=[[UIView alloc]initWithFrame:(CGRectMake(0, 0, 100, 100))]; HUDView.backgroundColor=[UIColor orangeColor]; HUDView.backgroundColor=[UIColor redColor]; HUDView.center = CGPointMake(100, 100); HUDView.layer.cornerRadius=50; [self.view addSubview:HUDView]; }

 

转载于:https://www.cnblogs.com/zhangsongbai/p/3488416.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值