IOS-UI-UIDynamic(二)
UIPushBehavior :推动效果
UIAttachmentBehavior:附着效果
UISnapBehavior:迅速移动效果
一.重要的属性
UIPushBehavior :推动效果
typedef NS_ENUM(NSInteger, UIPushBehaviorMode) {
UIPushBehaviorModeContinuous, 持续的力
UIPushBehaviorModeInstantaneous 瞬间的力
} NS_ENUM_AVAILABLE_IOS(7_0);
@property (nonatomic, readonly) UIPushBehaviorMode mode; 推动效果的样式
@property (nonatomic, readwrite) BOOL active; 是否激活
@property (readwrite, nonatomic) CGFloat angle; 推动角度
@property (readwrite, nonatomic) CGFloat magnitude; 推动力量
@property (readwrite, nonatomic) CGVector pushDirection; 推动的方向
UISnapBehavior:迅速移动效果
// The point argument is expressed in the reference coordinate system
- (instancetype)initWithItem:(id <UIDynamicItem>)item snapToPoint:(CGPoint)point;
迅速移动效果 只能一次 添加到一个元素上 snapToPoint 让他移动到哪一个点
@property (nonatomic, assign) CGFloat damping; // damping value from 0.0 to 1.0. 0.0 is the least oscillation. damping 的范围是(0.0-1.0)
UIAttachmentBehavior:附着效果
吸附着一个视图 或者一个点 (也可以多个连接)
附着效果 一个视图与一个锚点或者另一个视图相连接的情况
附着行为描述的是两点之间的连接情况,可以模拟刚性或者弹性连接
在多个物体间设定多个UIAttachmentBehavior,可以模拟多物体连接
typedef NS_ENUM(NSInteger, UIAttachmentBehaviorType) {
UIAttachmentBehaviorTypeItems, 吸附一个元素
UIAttachmentBehaviorTypeAnchor 吸附一个点
} NS_ENUM_AVAILABLE_IOS(7_0);
设置吸附效果的样式
@property (readonly, nonatomic) UIAttachmentBehaviorType attachedBehaviorType;
@property (readwrite, nonatomic) CGPoint anchorPoint;锚点
@property (readwrite, nonatomic) CGFloat length;距离 与锚点的距离
@property (readwrite, nonatomic) CGFloat damping; // 1: critical damping 跳跃度
@property (readwrite, nonatomic) CGFloat frequency; // in Hertz 幅度
二.代码
1.推动效果
#import "ViewController.h" @interface ViewController ()
{
UIDynamicAnimator * dynamicAnimator;
UIView *view1; }
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
dynamicAnimator = [[UIDynamicAnimator alloc]initWithReferenceView:self.view];
view1 = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushView)]; [view1 addGestureRecognizer:tap];
- (void)pushView{
[dynamicAnimator removeAllBehaviors];//移除所有的效果
UIPushBehavior * push = [[UIPushBehavior alloc]initWithItems:@[view1] mode:UIPushBehaviorModeContinuous];
// mode的两个属性
// UIPushBehaviorModeContinuous,一直推动
// UIPushBehaviorModeInstantaneous 瞬间推动
push.pushDirection = CGVectorMake(, );
// x是正右,负左。y是正下负上。
push.magnitude = ;//量级:既是推动力大小
//设置成NO时就不再响应效果
// push.active = NO;
[dynamicAnimator addBehavior:push];//把推动效果添加到效果器上
}
2.瞬间移动效果(viewDidLoad里面添加另一个点击手势)
UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(snap:)];
[self.view addGestureRecognizer:tap1];
之后
-(void)snap:(UITapGestureRecognizer *)send{
[dynamicAnimator removeAllBehaviors];
// 迅速移动效果 只能一次 添加到一个元素上 snapToPoint 让他移动到哪一个点
UISnapBehavior * snap = [[UISnapBehavior alloc]initWithItem:view1 snapToPoint:[send locationInView:self.view]];
//跳动幅度:0~1,值越小,跳动幅度越大
snap.damping = ;
[dynamicAnimator addBehavior:snap];
}
吸附效果
@interface ViewController ()
{
UIDynamicAnimator * dynamicAnimator;
UIView *view1;
UIView *view2;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
dynamicAnimator = [[UIDynamicAnimator alloc]initWithReferenceView:self.view];
view1 = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
view1.backgroundColor = [UIColor redColor]; [self.view addSubview:view1]; view2 = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
view2.backgroundColor = [UIColor blueColor];
[self.view addSubview:view2]; UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(attachment:)]; [self.view addGestureRecognizer:tap2]; }
-(void)attachment:(UITapGestureRecognizer *)send{
[dynamicAnimator removeAllBehaviors];
// 吸附到视图的某个点
UIAttachmentBehavior * attachment = [[UIAttachmentBehavior alloc]initWithItem:view1 offsetFromCenter:UIOffsetMake(, ) attachedToAnchor:[send locationInView:self.view]];
attachment.length = ;//吸附范围
attachment.damping = 0.5;
attachment.frequency = ;
[dynamicAnimator addBehavior:attachment];
// 两个元素吸附
// UIAttachmentBehavior *attachment1 = [[UIAttachmentBehavior alloc]initWithItem:view1 offsetFromCenter:UIOffsetMake(50, 50) attachedToItem:view2 offsetFromCenter:UIOffsetMake(50, 50)];
// attachment1.length = 50;//吸附范围
// attachment1.damping = 0.5;
// attachment1.frequency = 50;
// [dynamicAnimator addBehavior:attachment1];
}
另外,在iOS9之前这些效果只支持矩形。IOS9之后增加了新的属性UIDynamicItemCollisionBoundsType;因为本人的Xcode没升级,没法使用。
IOS-UI-UIDynamic(二)的更多相关文章
- 【HELLO WAKA】WAKA iOS客户端 之二 架构设计与实现篇
上一篇主要做了MAKA APP的需求分析,功能结构分解,架构分析,API分析,API数据结构分析. 这篇主要讲如何从零做iOS应用架构. 全系列 [HELLO WAKA]WAKA iOS客户端 之一 ...
- [IOS]IOS UI指南
[IOS]IOS UI指南 众所周知,IOS的界面设计,越来越流行,可以说都形成了一个标准,搜集了一些资料,供自己以后学习使用! iOS Human Interface Guidelines (中文翻 ...
- 微信连WiFi关注公众号流程更新 解决ios微信扫描二维码不关注就能上网的问题
前几天鼓捣了一下微信连WiFi功能,设置还蛮简单的,但ytkah发现如果是ios版微信扫描微信连WiFi生成的二维码不用关注公众号就可以直接上网了,而安卓版需要关注公众号才能上网,这样就少了很多ios ...
- XMPPFrameWork IOS 开发(二)- xcode配置
原始地址:XMPPFrameWork IOS 开发(二) 译文地址: Getting started using XMPPFramework on iOS 介绍 ios上的XMPPFramewor ...
- IOS UI 第八篇:基本UI
实现图片的滚动,并且自动停止在每张图片上 - (void)viewDidLoad{ [super viewDidLoad]; UIScrollView *scrollView = [[U ...
- 国外IOS UI指南
国外IOS UI指南 众所周知,IOS的界面设计,越来越流行,可以说都形成了一个标准,搜集了一些资料,供自己以后学习使用! iOS Human Interface Guidelines (中文翻译) ...
- iOS runtime探究(二): 从runtime開始深入理解OC消息转发机制
你要知道的runtime都在这里 转载请注明出处 http://blog.csdn.net/u014205968/article/details/67639289 本文主要解说runtime相关知识, ...
- iOS UI的几种模式
iOS UI的几种模式: 1.平凡模式(原生控件组合): 2.新闻模式: 3.播放器模式: 4.微博模式:
- 通过实现一个TableView来理解iOS UI编程
推荐一篇神作: 通过实现一个TableView来理解iOS UI编程 http://blog.jobbole.com/61101/
- UGUI的优点新UI系统二 直观、易于使用
UGUI的优点新UI系统二 直观.易于使用 对于UI控件,开发者可以直接使用鼠标在Scene视图里编辑它们的大小.位置和旋转角度,而无需编写任何代码,以Button为例,如图1-3.图1-4和图1 ...
随机推荐
- lazyload 图片延迟加载
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java foreach操作(遍历)数组
语法: 我们分别使用 for 和 foreach 语句来遍历数组 运行结果: 练习: import java.util.Arrays; public class HelloWorld { public ...
- ecshop在线手册前言及程序结构
该在线手册是有模版堂转载而来:仅供参考 一.前言 为什么我们ecshop模板堂要重制ecshop在线手册呢?因为目前网上的一些教程有些是比较老的,有些是不全面的,官方的手册也已经很久没有更 新,很多刚 ...
- Android最新锁屏病毒分析及解锁
一.情况简介 从去年开始PC端的敲诈者类病毒在不断的爆发,今年年初的时候手机上也开始出现了敲诈者之类的病毒,对这类病毒很无语也是趋势,因为很多时候病毒的产生是和金钱利益相关的.前天去吾爱破解论坛病 ...
- java中的AES 256算法遇到 Illegal key size or default parameters错的解决办法
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- nape.geom.MarchingSquares
Nape中的MarchingSquares类很简单,只有一个静态函数run,不过这对绘制那些简单的形状来说,已经足够了(当然MarchingSquares能做的不只这些).下面是这个run方法的结构: ...
- SQL 查询横表变竖表
SQL 查询横表变竖表 /*普通行列转换 假设有张学生成绩表(tb)如下:Name Subject Result张三 语文 74张三 数学 83张三 物理 93李四 语文 74李四 数学 84李四 ...
- oracle数据库表空间及归档
--表空间(TableSpace)是Oracle的开创性理念.表空间使得数据库管理更加灵活,而且极大地提高了数据库性能. --作用 :1.避免磁盘空间突然耗竭的风险 2.规划数据更灵活 3.提高数据库 ...
- 块设备驱动之NAND FLASH驱动程序
转载请注明出处:http://blog.csdn.net/ruoyunliufeng/article/details/25240909 一.框架总结 watermark/2/text/aHR0cDov ...
- select option jquery javascript
jQuery获取Select选择的Text和Value: $('#myselect').find('option:selected').attr('ent_id'); $('#ent_id' ...