iOS手势的综合运用
- //自定义一个VIEW封装手势功能
- // CustormView.m
- // gesterDemoo
- //
- // Created by ganchaobo on 13-7-13.
- // Copyright (c) 2013年 ganchaobo. All rights reserved.
- //
- #import "CustormView.h"
- @interface CustormView (){
- UIView *_parentview;
- CGPoint _lastCenter;
- }
- @end
- @implementation CustormView
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code
- }
- return self;
- }
- -(id)INitwithContetView:(UIView*)contentview ParentView:(UIView *)parentView{
- self=[super initWithFrame:contentview.bounds];
- UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
- UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
- [self addGestureRecognizer:tap];
- [self addGestureRecognizer:pan];
- [pan release];
- [tap release];
- _parentview=parentView;
- _lastCenter=self.center;
- return self;
- }
- -(void)pan:(UIPanGestureRecognizer *)pan{
- //移动点的位置
- CGPoint panPoint=[pan translationInView:_parentview];
- CGFloat x=pan.view.center.x+panPoint.x;
- NSLog(@"%f---->%f,--%f",panPoint.x,_lastCenter.x,x);
- if(x<_lastCenter.x){
- x=_lastCenter.x;
- }
- self.center=CGPointMake(x, _lastCenter.y);
- if(pan.state==UIGestureRecognizerStateEnded){
- [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
- if(x>){
- self.center=CGPointMake(, _lastCenter.y);
- }
- else{
- self.center=_lastCenter;
- }
- } completion:^(BOOL finished) {
- }];
- }
- [pan setTranslation:CGPointZero inView:self];
- }
- -(void)tap:(UITapGestureRecognizer *)tap{
- NSLog(@"tap");
- [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
- self.center=_lastCenter;
- } completion:^(BOOL finished) {
- }];
- }
- @end
- //
- // CustormView.m
- // gesterDemoo
- //
- // Created by ganchaobo on 13-7-13.
- // Copyright (c) 2013年 ganchaobo. All rights reserved.
- //
- #import "CustormView.h"
- @interface CustormView (){
- UIView *_parentview;
- CGPoint _lastCenter;
- }
- @end
- @implementation CustormView
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code
- }
- return self;
- }
- -(id)INitwithContetView:(UIView*)contentview ParentView:(UIView *)parentView{
- self=[super initWithFrame:contentview.bounds];
- UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
- UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
- [self addGestureRecognizer:tap];
- [self addGestureRecognizer:pan];
- [pan release];
- [tap release];
- _parentview=parentView;
- _lastCenter=self.center;
- return self;
- }
- -(void)pan:(UIPanGestureRecognizer *)pan{
- //移动点的位置
- CGPoint panPoint=[pan translationInView:_parentview];
- CGFloat x=pan.view.center.x+panPoint.x;
- NSLog(@"%f---->%f,--%f",panPoint.x,_lastCenter.x,x);
- if(x<_lastCenter.x){
- x=_lastCenter.x;
- }
- self.center=CGPointMake(x, _lastCenter.y);
- if(pan.state==UIGestureRecognizerStateEnded){
- [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
- if(x>){
- self.center=CGPointMake(, _lastCenter.y);
- }
- else{
- self.center=_lastCenter;
- }
- } completion:^(BOOL finished) {
- }];
- }
- [pan setTranslation:CGPointZero inView:self];
- }
- -(void)tap:(UITapGestureRecognizer *)tap{
- NSLog(@"tap");
- [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
- self.center=_lastCenter;
- } completion:^(BOOL finished) {
- }];
- }
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- UIView *firstview=[[UIView alloc] initWithFrame:self.view.bounds];
- firstview.backgroundColor=[UIColor redColor];
- [self.view addSubview:firstview];
- [firstview release];
- CustormView *view=[[CustormView alloc] INitwithContetView:self.view ParentView:self.view];
- view.backgroundColor=[UIColor yellowColor];
- [self.view addSubview:view];
- [view release];
- }
原文地址:http://blog.csdn.net/totogo2010/article/details/8622400
iOS手势的综合运用的更多相关文章
- ios手势
iOS 手势操作:拖动.捏合.旋转.点按.长按.轻扫.自定义 大 中 小 1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. i ...
- iOS手势学习UIGestureRecognizer & cocos2d 手势推荐
iOS手势学习UIGestureRecognizer & cocos2d 手势推荐 手势识别类型: UILongPressGestureRecognizer // 长按UIPanGestur ...
- iOS手势处理
iOS手势处理 iOS手势有着如下几种: UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecognizer UIS ...
- iOS 手势识别器概述
手势识别器 iOS 手势识别器(UIGestureRecognizer) 点击手势(UITapGestureRecognizer) 滑动手势(UISwipeGestureRecognizer) 旋转手 ...
- swift 实现iOS手势密码、指纹密码、faceID
本博客包含了如何实现iOS手势密码.指纹密码.faceID全步骤,包括了完整的代码. 先附上demo地址https://github.com/Liuyubao/LYBTouchID,支持swift3. ...
- iOS手势解锁、指纹解锁--Swift代码
一.手势密码 1. 1.1.用UIButton组成手势的节点. 1.2.当手指接触屏幕时,调用重写的 touchesBegan:withEvent方法(在touchesBegan里调用setNeeds ...
- IOS 手势-轻点、触摸、手势、事件
1.概念 手势是从你用一个或多个手指接触屏幕时开始,直到手指离开屏幕为止所发生的所有事件.无论手势持续多长时间,只要一个或多个手指仍在屏幕上,这个手势就存在. 触摸是指把手指放到IOS设备的屏幕上,从 ...
- IOS 手势详解
在IOS中手势可以让用户有很好的体验,因此我们有必要去了解一下手势. (在设置手势是有很多值得注意的地方) *是需要设置为Yes的点击无法响应* *要把手势添加到所需点击的View,否则无法响应* 手 ...
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义
1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureReco ...
随机推荐
- 服务器主机上RAID Controller的Read Ahead Policy
RAID控制器(卡)会根据Read Ahead Policy 来决定是否只读取应用程序所请求的一块数据, 还是从硬盘上读取整个stripe. 这个policy会对读的性能产生影响. No Read A ...
- JQuery效率问题
1,前言 我们开发了一个专题系统,生成了JSON的数据格式,采用JQuery动态插入HTML中,在前期的使用中,没有太大的问题,效率还可以接受,但是最近可能由于网络加之页面设计问题,我们的JS效率比较 ...
- Red Hat 配置ip地址
red hat 的网卡配置文件位于:/etc/sysconfig/network-scripts目录下,如ifcfg-eth0,ifcfg-eth1等等,下面进行配置: 1)DEVICE=eth0 定 ...
- POJ 1265 pick定理
pick公式:多边形的面积=多边形边上的格点数目/2+多边形内部的格点数目-1. 多边形边上的格点数目可以枚举每条边求出.如果是水平或者垂直,显然可以得到,否则则是坐标差的最大公约数减1.(注这里是不 ...
- NLP系列(4)_朴素贝叶斯实战与进阶(转)
http://blog.csdn.net/han_xiaoyang/article/details/50629608 作者: 寒小阳 && 龙心尘 时间:2016年2月. 出处:htt ...
- Centos6.4下安装protobuf及简单使用
1.protobuf是google公司提出的数据存储格式,详细介绍可以参考:https://code.google.com/p/protobuf/ 2.下载最新的protobuf,下载地址:https ...
- Creating OpenGL 4.3 window fails with GLFW3
I set up a minimal application to open a blank window with GLFW3: #include <iostream> #inclu ...
- oauth2-server-php-docs 存储 学说2
学说2 创建客户端和访问令牌存储 要把学说融入到你的项目中,首先要建立你的实体.我们先从客户端,用户和访问令牌模型开始: yaml YourNamespace\Entity\OAuthClient: ...
- Springmvc 上传文件MultipartFile 转File
转自:http://blog.csdn.net/boneix/article/details/51303207 业务场景:ssm框架 上传文件到应用服务器过程中要传到专有的文件服务器并返回url进行其 ...
- matlab之simulink仿真入门
Matlab Simulink仿真工具的应用 ****Simulink是一个用来对动态系统进行建模.仿真和分析的软件包.使用Simulink来建模.分析和仿真各种动态系统(包含连续系统.离散系统和混合 ...