//自定义一个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. window.location属性用法及解决一个window.location.search为什么为空的问题

    通常用window.location该属性获取页面 URL 地址: 1.什么是window.location? 比如URL:http://b.a.com:88/index.php?name=kang& ...

  2. Android -- Volley解析

    Volley设计 Dispatch Thread不断从RequestQueue中取出请求,根据是否已缓存调用Cache或Network这两类数据获取接口之一,从内存缓存或是服务器取得请求的数据,然后交 ...

  3. 2017 年度码云新增项目排行榜 TOP 50,为它们打“call”

    2017 年度码云新增项目排行榜 TOP 50 正式出炉 !2017 结束了,我们来关注一下这一年里码云上新增的最热门的开源项目吧.此榜单根据 2017 年在码云上新增开源项目的 Watch.Star ...

  4. css文件放在根目录之后不起作用原因

    修改为

  5. centos:时间同步

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

  6. Spring(十五):通过注解配置 Bean

    在ClassPath中扫描组件 1)组件扫描(component scanning):Spring能够从classpath下自动扫描,侦测和实例化具有特定注解的组件: 2)特定组件包含: --- @C ...

  7. 设置py文件的路径

    想在IDLE中打开py文件,需要设置PYTHONPATH环境变量: 设置后,就能在IDLE的Path Browser中看到sys.path了: 然后,就可以用import了

  8. C# winForm webBrowser页面中js调用winForm类方法(转)

      有时我们在winform项目中嵌入了网页,想通过html页面调用后台方法,如何实现呢?其实很简单,主要有三部:   1.在被调用方法类上加上[ComVisible(true)]标签,意思就是当前类 ...

  9. 在java中像js那样处理json数据

    工作中经常需要通过ajax向前台返回json数据,都是通过拼字符串拼出来的,很发麻烦不说,还容易出错. 于是想,能不能像js那样操作json呢?或者说更方便的操作呢? Google的gson就是这样的 ...

  10. .NET Framework 工具

    您可以使用 .NET Framework 工具轻松创建.部署和管理面向 .NET Framework 的应用程序和组件. 此节中介绍的大部分 .NET Framework 工具将自动随 Visual ...