UIDynamic-附着行为:UIAttachmentBehavior
直接上代码:
//
// YFAttachmentBehaviorViewController.m
// BigShow1949
//
// Created by apple on 16/8/25.
// Copyright © 2016年 BigShowCompany. All rights reserved.
// #import "YFAttachmentBehaviorViewController.h" @interface YFAttachmentBehaviorViewController () @property (nonatomic, strong) UIView *square1;
@property(nonatomic,strong)UIDynamicAnimator *animator;
@property (nonatomic, strong) UIAttachmentBehavior *attachmentBehavior; @end @implementation YFAttachmentBehaviorViewController - (void)viewDidLoad
{
[super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; // 创建一个正方形
self.square1 =[[UIView alloc] initWithFrame: CGRectMake(0.0f, -, 80.0f, 80.0f)];
self.square1.backgroundColor = [UIColor greenColor];
self.square1.center = self.view.center;
[self.view addSubview:self.square1]; self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; UICollisionBehavior* collision = [[UICollisionBehavior alloc] initWithItems:@[self.square1]];
collision.translatesReferenceBoundsIntoBoundary = YES; UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[self.square1]]; [self.animator addBehavior:collision];
[self.animator addBehavior:gravity]; // 视图手势
[self createGestureRecognizer];
} - (void)createGestureRecognizer{
UIPanGestureRecognizer *tapGestureRecognizer =
[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self.view addGestureRecognizer:tapGestureRecognizer];
} - (void)handleTap:(UIPanGestureRecognizer *)gesture{ if (gesture.state == UIGestureRecognizerStateBegan){
NSLog(@"----Began"); CGPoint squareCenterPoint = CGPointMake(self.square1.center.x, self.square1.center.y - 100.0); UIAttachmentBehavior* attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.square1 attachedToAnchor:squareCenterPoint]; self.attachmentBehavior = attachmentBehavior;
[self.animator addBehavior:attachmentBehavior]; } else if ( gesture.state == UIGestureRecognizerStateChanged) {
NSLog(@"----Changed");
[self.attachmentBehavior setAnchorPoint:[gesture locationInView:self.view]]; } else if (gesture.state == UIGestureRecognizerStateEnded) {
NSLog(@"----Ended");
[self.animator removeBehavior:self.attachmentBehavior];
}
} @end
UIDynamic-附着行为:UIAttachmentBehavior的更多相关文章
- 滚珠菜单动效-b
原型从网上找的,动效使用了CAAnimation和UIDynamic物理引擎. gitHub :https://github.com/BearRan/FlowMenuAnimation 大致步骤如 ...
- UIDynamic(简单介绍)
一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟和仿真现实生活中的物理现象 如:重力.弹性碰撞等现 ...
- iOS开发——高级篇——UIDynamic 物理引擎
一.UIDynamic 1.简介什么是UIDynamicUIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架可以认为是一种物理引擎,能模拟和仿真现实生活中的物理现象重力.弹性碰撞 ...
- UIDynamic(物理仿真)
简介 什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟和仿真现实生活中的物理现象 如: 重力.弹性碰撞等现象 物理引 ...
- iOS开发拓展篇—UIDynamic(简单介绍)
iOS开发拓展篇—UIDynamic(简单介绍) 一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟 ...
- UIDynamic仿物理引擎-浮动碰撞效果-b
最近产品提了个需求(电商的APP-两鲜),需要在APP背景加上几个水果图案在那里无规则缓慢游荡...模仿 天天果园 APP的.好吧,那我就在网上找了很多文章,总结一下写个demo.效果如下: Mou ...
- UIDynamic 基础认识
UIDynamic 是从iOS 7开始引入的一种新技术,属于UIKit框架,可以模拟现实生活中的物理现象,如:碰撞.抖动.摆动等 动力效果:有一个效果器,叫做“动力效果器”里面面可以添加“动力效果” ...
- 李洪强iOS开发之拓展篇—UIDynamic(简单介绍)
iOS开发拓展篇—UIDynamic(简单介绍) 一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能 ...
- iOS开发——UI篇OC篇&UIDynamic详解
iOS开发拓展篇—UIDynamic(简单介绍) 一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟 ...
- iOS基础 - UIDynamic
一.UIKit动力学 UIKit动力学最大的特点是将现实世界动力驱动的动画引入了UIKit,比如重力,铰链连接,碰撞,悬挂等效果,即将2D物理引擎引入了UIKit 注意:UIKit动力学的引入,并不是 ...
随机推荐
- Android Support Library介绍
v4 Support Library 这个库是为Android 1.6(API版本为4)及以上的版本设计的,它包含大部分高版本中有而低版本中没有的API,包括application component ...
- MVC缺点
MVC的不足之处表现在以下几个方面: (1) 增加了系统结构和实现的复杂性.对于简单的界面,严格遵循MVC,使模型.视图与控制器分离,会增加结构的复杂性,并可能产生过多的更新操作,降低运行效率. (2 ...
- TextInputLayout setError() setErrorEnable()
public void afterTextChanged(Editable s) { if (textInputLayout.getEditText().getText().toString().le ...
- 正则表达式的JS验证
/判断输入内容是否为空 function IsNull(){ var str = document.getElementById('str').value.trim(); ...
- js中的运算总结(未完待续
[74由几个1几个5几个10几个20组成] var num = 74; for(one = 0; one <= num; one++){ for(five = 0; five <= num ...
- #研发解决方案#基于Apriori算法的Nginx+Lua+ELK异常流量拦截方案
郑昀 基于杨海波的设计文档 创建于2015/8/13 最后更新于2015/8/25 关键词:异常流量.rate limiting.Nginx.Apriori.频繁项集.先验算法.Lua.ELK 本文档 ...
- Linux命令学习总结: file命令
命令简介: 该命令用来识别文件类型,也可用来辨别一些文件的编码格式.它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的. 执行权限 :All User 指令所在 ...
- Symantec Backup Exec 2012 Agent For Linux安装
Backup Exec 2012 介绍 Backup Exec 2012 是一种为虚拟和物理环境提供保护的集成产品,能够简化备份和灾难恢复,并提供了无可匹敌的恢复功能.借助于强大的 Symantec ...
- jQuery 中的 39 个技巧
1.当document文档就绪时执行JavaScript代码. 我们为什么使用jQuery库呢?原因之一就在于我们可以使jQuery代码在各种不同的浏览器和存在bug的浏览器上完美运行. <sc ...
- codevs 1115 开心的金明--01背包
1115 开心的金明 2006年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 金明今天很开心,家里购 ...