UIDynamic使用
来源:互联网 发布:骑马与砍杀火与剑优化 编辑:程序博客网 时间:2024/06/06 00:15
//// ViewController.m// UIDynamic//// Created by hq on 16/5/3.// Copyright © 2016年 hanqing. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIImageView *ball;@property (weak, nonatomic) IBOutlet UIView *bottomVIew;@property(nonatomic,strong) UIDynamicAnimator *anim;@end@implementation ViewController-(UIDynamicAnimator *)anim{ //设置仿真范围 if (_anim==nil) { _anim=[[UIDynamicAnimator alloc]initWithReferenceView:self.view]; } return _anim;}- (void)viewDidLoad { [super viewDidLoad]; }-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch *touch=[touches anyObject]; CGPoint currentP=[touch locationInView:self.view]; //创建一个捕捉行为 UISnapBehavior *snap=[[UISnapBehavior alloc]initWithItem:self.ball snapToPoint:currentP]; //防抖系数,越小,越抖,最大值为1 snap.damping=0; //必须清空上一次的才能继续使用 [self.anim removeAllBehaviors]; [self.anim addBehavior:snap];}-(void) testCollisionBehaviorByPath{ //创建一个碰撞行为 UICollisionBehavior *coll=[[UICollisionBehavior alloc] init]; //添加一个碰撞的边界(路径) UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width)]; [coll addBoundaryWithIdentifier:@"path" forPath:path]; [coll addItem:self.ball]; //[coll addItem:self.bottomVIew]; UIGravityBehavior *grav=[[UIGravityBehavior alloc] init]; [grav addItem:self.ball]; [self.anim addBehavior:coll]; [self.anim addBehavior:grav]; }//碰撞边界为用线围起来的一块区域-(void) testCollisionBehavior1{ //创建一个碰撞行为 UICollisionBehavior *coll=[[UICollisionBehavior alloc] init]; //添加一个碰撞的边界 [coll addBoundaryWithIdentifier:@"line1" fromPoint:CGPointMake(0, 0) toPoint:CGPointMake(0, self.view.bounds.size.height*0.5)]; [coll addBoundaryWithIdentifier:@"line2" fromPoint:CGPointMake(0, self.view.bounds.size.height*0.5) toPoint:CGPointMake(self.view.bounds.size.width, self.view.bounds.size.height)]; [coll addItem:self.ball]; [coll addItem:self.bottomVIew]; UIGravityBehavior *grav=[[UIGravityBehavior alloc] init]; [grav addItem:self.ball]; [self.anim addBehavior:coll]; [self.anim addBehavior:grav];}//重力仿真器-(void) testGravity{ //创建xx的仿真行为 UIGravityBehavior *grav=[[UIGravityBehavior alloc]init]; [grav addItem:self.ball]; [self.anim addBehavior:grav]; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; }@end
0 0
- UIDynamic使用
- UIDynamic的基本使用
- UIDynamic的使用
- UIdynamic的简单使用
- UIDynamic
- UIDynamic
- 【iOS】UIDynamic
- 、UIDynamic介绍
- UIDynamic注意事项
- UIDynamic介绍
- UIDynamic 动画
- 动画-UIDynamic
- UIDynamic 简单介绍
- UIDynamic(简单介绍)
- iOS-UIDynamic-UIKit
- UIDynamic-动力效果
- iOS7 物理动力学UIDynamic
- iOS 开发之UIDynamic
- SSH整合开发(一)
- web debugger fiddler 使用小结
- AYITACM2016省赛第三周 G - Unidirectional TSP(DP单向旅行商问题)
- linux crontab定时任务详解
- Java数据类型——主要讲基本数据类型
- UIDynamic使用
- 浅析Java中的访问权限控制
- shop++二次开发分享(新增编号类型)
- struts2访问三大域和参数
- c++第四次上机实验
- 在Linux中,设置前、后台命令和程序的执行
- 《接口自动化测试实战》第一讲 读取用例数据
- HandlerThread源码分析及使用
- 七大查找算法