//自定义一个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手势的综合运用的更多相关文章

  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. Convert Sorted List to Binary Search Tree leetcode java

    题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height ...

  2. LigerUi之Grid使用详解(二)——数据编辑

    一.问题概述 在开发web信息管理系统时,使用Web前端框架可以帮助我们快速搭建一组风格统一的界面效果,而且能够解决大多数浏览器兼容问题,提升开发效率.所以上一篇文章为大家介绍了LigerGrid的显 ...

  3. MFC路径层的使用(BeginPath和EndPath函数)

    响应WM_PAINT消息的代码如下: void CTextView::OnDraw(CDC* pDC) { CTextDoc* pDoc = GetDocument(); ASSERT_VALID(p ...

  4. Android -- DiskLruCache

    DiskLruCache 创建一个磁盘缓存对象: public static DiskLruCache open(File directory, int appVersion, int valueCo ...

  5. 【Java】Java-UTC-时间戳处理

    Java-UTC-时间戳处理 java utc 时间戳_百度搜索 JAVA获取时间戳,哪个更快 - 潇湘客 - ITeye博客 Java获取UTC时间的方法详解_java_脚本之家 Java UTC时 ...

  6. 建模角度理解word embedding及tensorflow实现

    http://www.jianshu.com/p/d44ce1e3ec2f 1. 前言 本篇主要介绍关键词的向量表示,也就是大家熟悉的word embedding.自Google 2013 年开源wo ...

  7. centos:时间同步

    转自:https://blog.csdn.net/u011391839/article/details/62892020 Linux的时间分为System Clock(系统时间)和Real Time ...

  8. 模拟日历计算 poj1008

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 69932   Accepted: 21524 D ...

  9. Python 使用pymongo操作mongodb库

    Python 使用pymongo操作mongodb库 2016-12-31 21:55 1115人阅读 评论(0) 收藏 举报  分类: - - - Python(10)  版权声明:本文为博主原创文 ...

  10. photoshop 雪碧图制作

    图片拖入后 一般取同行同列最高最宽 自动在所选目录生成 打开: 修改 四次请求有点多啊. 打开 (下载)css sprite 自动生成坐标地址. 不过我们要把它排远一点 OK了. 我们生成以后: 坐标 ...