1. //自定义一个VIEW封装手势功能
  2. // CustormView.m
  3. // gesterDemoo
  4. //
  5. // Created by ganchaobo on 13-7-13.
  6. // Copyright (c) 2013年 ganchaobo. All rights reserved.
  7. //
  8.  
  9. #import "CustormView.h"
  10.  
  11. @interface CustormView (){
  12. UIView *_parentview;
  13. CGPoint _lastCenter;
  14. }
  15.  
  16. @end
  17.  
  18. @implementation CustormView
  19.  
  20. - (id)initWithFrame:(CGRect)frame
  21. {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. // Initialization code
  25. }
  26. return self;
  27. }
  28.  
  29. -(id)INitwithContetView:(UIView*)contentview ParentView:(UIView *)parentView{
  30. self=[super initWithFrame:contentview.bounds];
  31. UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
  32. UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
  33. [self addGestureRecognizer:tap];
  34. [self addGestureRecognizer:pan];
  35. [pan release];
  36. [tap release];
  37. _parentview=parentView;
  38. _lastCenter=self.center;
  39. return self;
  40.  
  41. }
  42.  
  43. -(void)pan:(UIPanGestureRecognizer *)pan{
  44. //移动点的位置
  45. CGPoint panPoint=[pan translationInView:_parentview];
  46. CGFloat x=pan.view.center.x+panPoint.x;
  47. NSLog(@"%f---->%f,--%f",panPoint.x,_lastCenter.x,x);
  48. if(x<_lastCenter.x){
  49. x=_lastCenter.x;
  50. }
  51.  
  52. self.center=CGPointMake(x, _lastCenter.y);
  53.  
  54. if(pan.state==UIGestureRecognizerStateEnded){
  55.  
  56. [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
  57. if(x>){
  58. self.center=CGPointMake(, _lastCenter.y);
  59. }
  60. else{
  61. self.center=_lastCenter;
  62. }
  63.  
  64. } completion:^(BOOL finished) {
  65.  
  66. }];
  67. }
  68. [pan setTranslation:CGPointZero inView:self];
  69. }
  70.  
  71. -(void)tap:(UITapGestureRecognizer *)tap{
  72. NSLog(@"tap");
  73. [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
  74. self.center=_lastCenter;
  75. } completion:^(BOOL finished) {
  76.  
  77. }];
  78. }
  79.  
  80. @end
  1. //
  2. // CustormView.m
  3. // gesterDemoo
  4. //
  5. // Created by ganchaobo on 13-7-13.
  6. // Copyright (c) 2013年 ganchaobo. All rights reserved.
  7. //
  8.  
  9. #import "CustormView.h"
  10.  
  11. @interface CustormView (){
  12. UIView *_parentview;
  13. CGPoint _lastCenter;
  14. }
  15.  
  16. @end
  17.  
  18. @implementation CustormView
  19.  
  20. - (id)initWithFrame:(CGRect)frame
  21. {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. // Initialization code
  25. }
  26. return self;
  27. }
  28.  
  29. -(id)INitwithContetView:(UIView*)contentview ParentView:(UIView *)parentView{
  30. self=[super initWithFrame:contentview.bounds];
  31. UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
  32. UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
  33. [self addGestureRecognizer:tap];
  34. [self addGestureRecognizer:pan];
  35. [pan release];
  36. [tap release];
  37. _parentview=parentView;
  38. _lastCenter=self.center;
  39. return self;
  40.  
  41. }
  42.  
  43. -(void)pan:(UIPanGestureRecognizer *)pan{
  44. //移动点的位置
  45. CGPoint panPoint=[pan translationInView:_parentview];
  46. CGFloat x=pan.view.center.x+panPoint.x;
  47. NSLog(@"%f---->%f,--%f",panPoint.x,_lastCenter.x,x);
  48. if(x<_lastCenter.x){
  49. x=_lastCenter.x;
  50. }
  51.  
  52. self.center=CGPointMake(x, _lastCenter.y);
  53.  
  54. if(pan.state==UIGestureRecognizerStateEnded){
  55.  
  56. [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
  57. if(x>){
  58. self.center=CGPointMake(, _lastCenter.y);
  59. }
  60. else{
  61. self.center=_lastCenter;
  62. }
  63.  
  64. } completion:^(BOOL finished) {
  65.  
  66. }];
  67. }
  68. [pan setTranslation:CGPointZero inView:self];
  69. }
  70.  
  71. -(void)tap:(UITapGestureRecognizer *)tap{
  72. NSLog(@"tap");
  73. [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
  74. self.center=_lastCenter;
  75. } completion:^(BOOL finished) {
  76.  
  77. }];
  78. }
  79.  
  80. @end
  1. @implementation ViewController
  2.  
  3. - (void)viewDidLoad
  4. {
  5. [super viewDidLoad];
  6. // Do any additional setup after loading the view, typically from a nib.
  7. UIView *firstview=[[UIView alloc] initWithFrame:self.view.bounds];
  8. firstview.backgroundColor=[UIColor redColor];
  9. [self.view addSubview:firstview];
  10. [firstview release];
  11.  
  12. CustormView *view=[[CustormView alloc] INitwithContetView:self.view ParentView:self.view];
  13. view.backgroundColor=[UIColor yellowColor];
  14. [self.view addSubview:view];
  15. [view release];
  16.  
  17. }

原文地址:http://blog.csdn.net/totogo2010/article/details/8622400

iOS手势的综合运用的更多相关文章

  1. ios手势

    iOS 手势操作:拖动.捏合.旋转.点按.长按.轻扫.自定义 大 中 小   1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. i ...

  2. iOS手势学习UIGestureRecognizer & cocos2d 手势推荐

    iOS手势学习UIGestureRecognizer & cocos2d 手势推荐 手势识别类型: UILongPressGestureRecognizer  // 长按UIPanGestur ...

  3. iOS手势处理

    iOS手势处理 iOS手势有着如下几种: UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecognizer UIS ...

  4. iOS 手势识别器概述

    手势识别器 iOS 手势识别器(UIGestureRecognizer) 点击手势(UITapGestureRecognizer) 滑动手势(UISwipeGestureRecognizer) 旋转手 ...

  5. swift 实现iOS手势密码、指纹密码、faceID

    本博客包含了如何实现iOS手势密码.指纹密码.faceID全步骤,包括了完整的代码. 先附上demo地址https://github.com/Liuyubao/LYBTouchID,支持swift3. ...

  6. iOS手势解锁、指纹解锁--Swift代码

    一.手势密码 1. 1.1.用UIButton组成手势的节点. 1.2.当手指接触屏幕时,调用重写的 touchesBegan:withEvent方法(在touchesBegan里调用setNeeds ...

  7. IOS 手势-轻点、触摸、手势、事件

    1.概念 手势是从你用一个或多个手指接触屏幕时开始,直到手指离开屏幕为止所发生的所有事件.无论手势持续多长时间,只要一个或多个手指仍在屏幕上,这个手势就存在. 触摸是指把手指放到IOS设备的屏幕上,从 ...

  8. IOS 手势详解

    在IOS中手势可以让用户有很好的体验,因此我们有必要去了解一下手势. (在设置手势是有很多值得注意的地方) *是需要设置为Yes的点击无法响应* *要把手势添加到所需点击的View,否则无法响应* 手 ...

  9. iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义

    1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureReco ...

随机推荐

  1. 服务器主机上RAID Controller的Read Ahead Policy

    RAID控制器(卡)会根据Read Ahead Policy 来决定是否只读取应用程序所请求的一块数据, 还是从硬盘上读取整个stripe. 这个policy会对读的性能产生影响. No Read A ...

  2. JQuery效率问题

    1,前言 我们开发了一个专题系统,生成了JSON的数据格式,采用JQuery动态插入HTML中,在前期的使用中,没有太大的问题,效率还可以接受,但是最近可能由于网络加之页面设计问题,我们的JS效率比较 ...

  3. Red Hat 配置ip地址

    red hat 的网卡配置文件位于:/etc/sysconfig/network-scripts目录下,如ifcfg-eth0,ifcfg-eth1等等,下面进行配置: 1)DEVICE=eth0 定 ...

  4. POJ 1265 pick定理

    pick公式:多边形的面积=多边形边上的格点数目/2+多边形内部的格点数目-1. 多边形边上的格点数目可以枚举每条边求出.如果是水平或者垂直,显然可以得到,否则则是坐标差的最大公约数减1.(注这里是不 ...

  5. NLP系列(4)_朴素贝叶斯实战与进阶(转)

    http://blog.csdn.net/han_xiaoyang/article/details/50629608 作者: 寒小阳 && 龙心尘 时间:2016年2月. 出处:htt ...

  6. Centos6.4下安装protobuf及简单使用

    1.protobuf是google公司提出的数据存储格式,详细介绍可以参考:https://code.google.com/p/protobuf/ 2.下载最新的protobuf,下载地址:https ...

  7. Creating OpenGL 4.3 window fails with GLFW3

      I set up a minimal application to open a blank window with GLFW3: #include <iostream> #inclu ...

  8. oauth2-server-php-docs 存储 学说2

    学说2 创建客户端和访问令牌存储 要把学说融入到你的项目中,首先要建立你的实体.我们先从客户端,用户和访问令牌模型开始: yaml YourNamespace\Entity\OAuthClient: ...

  9. Springmvc 上传文件MultipartFile 转File

    转自:http://blog.csdn.net/boneix/article/details/51303207 业务场景:ssm框架 上传文件到应用服务器过程中要传到专有的文件服务器并返回url进行其 ...

  10. matlab之simulink仿真入门

    Matlab Simulink仿真工具的应用 ****Simulink是一个用来对动态系统进行建模.仿真和分析的软件包.使用Simulink来建模.分析和仿真各种动态系统(包含连续系统.离散系统和混合 ...