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动力学的引入,并不是 ...
随机推荐
- 浅谈Bluetooth蓝牙开发
前言:项目用到蓝牙开发,具体蓝牙获取硬件传感器中的数据. 因为没有蓝牙开发的相关经验,决定先了解一些蓝牙开发的知识,再去看之前同事写的蓝牙相关代码. ------------------------- ...
- 适配iOS 10以及Xcode 8(转载)
一.证书管理 用Xcode8打开工程后,比较明显的就是下图了,这个是苹果的新特性,可以帮助我们自动管理证书.建议大家勾选这个Automatically manage signing(Ps.但是在bea ...
- 4-printf & scanf函数
一.printf函数 这是(printf和scanf)在stdio.h中声明的一个函数,因此使用前必须加入#include <stdio.h> 1.用法 1> printf(字符串) ...
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a ...
- Linux 如何查看修改DNS配置
DNS服务器介绍 DNS是计算机域名系统(Domain Name System 或Domain Name Service) 的缩写,它是由域名解析器和域名服务器组成的.域名服务器是指保存有该网络中所有 ...
- String与int之间的转换
原文: http://www.360doc.com/content/10/1215/00/2258566_78225883.shtml
- CentOS系统 yum 安装 iftop实时流量监控工具
一. 不多说其他的无用话题.直接看步骤: 1.要安装某个工具,首先得知道这个工具需要依赖包. eg:iftop 就依赖 以下这几个依赖包(不清楚工具依赖什么包“Google.百度”). flex ...
- openstack-swift云存储部署(二)
接上篇,swift-proxy和swift-store的安装 先说一下服务器分配 swift-proxy和keystone部署在192.168.25.11 swift-store是两台 分别是192 ...
- [已解决]Teamviewer VPN 连接上,但无法ping
用Teamveiwer 可以进行远程控制连接.用了VPN功能后,起先也正常.可以PING和其他网络操作. 后来忽然始终VPN连接上后,无法PING和做其他的网络操作了. 检查缘由是对方TeamView ...
- Tips for Planning Your Business Startup
原文链接:http://domaintree.me/?p=1037 By Robert Thibodeau – Starting a business can be a very daunting ...