//移动手势创建---
UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan_Click:)];
[self.view addGestureRecognizer:pan];
//移动手势函数
-(void)pan_Click:(UIPanGestureRecognizer *)sender{
//拖拽效果是同过改变视图坐标来实现的
//表格偏移量 = 手势偏移量 【向右】
//先获得手势坐标
CGPoint p=[sender locationInView:self.view];
//判断手势状态是不是拖拽开始
if (sender.state==UIGestureRecognizerStateBegan) {
//手势开始时的坐标
starPoint=p;
}
//判断手势移动的方向
if (p.x>starPoint.x+100) { //说明是要向右移动
if (ce.frame.origin.x==-200 ) {
return;
}else {
if (ce.frame.origin.x!=-100) {
//tv2的值 会随着手势的x的变化而变化
ce.frame=CGRectMake(p.x-starPoint.x-300, 0, 300, 667);
}
}
}else {
if (ce.frame.origin.x!=-300 ) {
//让tv2随手势变化而变化
ce.frame=CGRectMake(-100+(p.x-starPoint.x), 0,300, 667);
}
}
//判断手势的结束状态
if (sender.state==UIGestureRecognizerStateEnded) {
if (ce.frame.origin.x>-200) {
[UIView animateWithDuration:0.2 animations:^{
ce.frame=CGRectMake(-100, 0,300, 667);
}];
open=YES;
[self AddView];
}else{
[UIView animateWithDuration:0.2 animations:^{
ce.frame=CGRectMake(-300, 0,300, 667);
}];
open=NO;
[btOpen removeFromSuperview];
}
}
}