UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[self.pushToHomeButton addGestureRecognizer:pan];
#pragma mark - 手势执行的方法
-(void)handlePan:(UIPanGestureRecognizer *)rec{
//返回在横坐标上、纵坐标上拖动了多少像素
CGPoint point=[rec translationInView:self.view];
rec.view.center=CGPointMake(rec.view.center.x+point.x, rec.view.center.y+point.y);
//拖动完之后,每次都要用setTranslation:方法制0这样才不至于不受控制般滑动出视图
[rec setTranslation:CGPointMake(0, 0) inView:self.view];
if(rec.state == UIGestureRecognizerStateEnded || rec.state == UIGestureRecognizerStateCancelled)//拖动结束
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
rec.view.frame = CGRectMake(300*BILI, rec.view.frame.origin.y, 63*BILI, 63*BILI);
[UIView commitAnimations];
}
}