iOS手势的综合运用
2024-10-12 23:43:25
//自定义一个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
最新文章
- ERROR 1300 (HY000): Invalid utf8 character string: &#39;&#39;
- SharePoint Server 2013开发之旅(二):使用在线的开发人员网站进行SharePoint App开发
- Scrum Meeting (Oct. 27 2014)
- CLR调试报错“Visual Studio远程调试监视器 (MSVSMON.EXE) 的 64 位版本无法调试 32 位进程或 32 位转储。请改用 32 位版本”的解决
- 夺命雷公狗---node.js---20之项目的构建在node+express+mongo的博客项目5mongodb在项目中实现添加数据
- 利用DetachedCriteria实现模糊查询和分页
- Laxcus大数据管理系统2.0(11)- 第九章 容错
- 关于System.Collections空间
- Hadoop MapReduce概念学习系列之mr程序详谈(二十三)
- cookie、localStorage、sessionStorage之间的区别
- C#用注册表开机自动启动某某软件
- IOC原理分析
- vmware 使用技巧
- iOS基础 - UIDatePicker and UIPickerView and UITextField
- cocos2d-x学习之路之工作吐槽
- linq给list集合数据分页
- HTML5 full-screen全屏API
- A1125. Chain the Ropes
- 使用jwt
- 〖Linux〗让Kubuntu的“启动栏”与Win7“任务栏”的界面和功能一样