//自定义一个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. 构建-0 Gradle DSL 属性和方法【API】

    Android Plugin DSL Reference This is the DSL reference for Android Gradle Plugin. Start reading by f ...

  2. Openstack中为虚拟机使用CDROM光驱设备

    在Libvirt里处理 在nova里处理 实际效果 怎么卸载 在Libvirt里处理 尝试了下面有几种方法,为虚拟机载入光盘文件: 1.使用ide方式挂载: virsh attach-disk {in ...

  3. Qt5.3.1 静态编译的configure

    今天最终自己静态编译过了QT5.3.1, 成功用在项目上了, 记录下configure指令.  configure -confirm-license -opensource -platform win ...

  4. fastjson生成json时Null属性不显示 (转)

    http://blog.csdn.net/u010648555/article/details/51422340 null对应的key已经被过滤掉:这明显不是我们想要的结果,这时我们就需要用到fast ...

  5. Java归去来第3集:Eclipse中给动态模块升级

    一.前言 如果还不了解剧情,请返回第2集的剧情          Java归去来第2集:利用Eclipse创建Maven Web项目 二.开始升级动态模块 2.1:查看原来的版本 我们先来看看Ecli ...

  6. Get file extention in XSLT

      When working with data view web parts or data form web parts in SharePoint, you might want to use ...

  7. easyui datagrid实现拖动表头

    $.extend($.fn.datagrid.methods, { columnMoving: function (jq) { return jq.each(function () { var tar ...

  8. 程序员的福音,AI可以自动修复bug了!

    人工智能完全学会自己编程,可能说起来还有一种科幻感,但 AI 帮程序员找 bug 这件事,已经达到了不错的水平. 北京大学.微软亚洲研究院和中国电子科技大学就一起尝试着让 AI 找 bug.微软亚洲研 ...

  9. Linux开机自动启动某一程序

    Linux开机启动程序详解我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. ...

  10. mysql版本导致的hibernate 方言问题

    今天在看hibernate视频时,看到视频上人家的hibernate.cfg.xml配置文件在配置hibernate方言时,发现视频上是这样写的<property name="dial ...