- (void) doHandlePanAction:(UIPanGestureRecognizer *)paramSender {
CGPoint point = [paramSender translationInView:self.view];
CGPoint newCenter = CGPointMake(paramSender.view.center.x + point.x, paramSender.view.center.y + point.y);//限制屏幕范围:
newCenter.y = MAX(paramSender.view.height/2, newCenter.y);
newCenter.y = MIN(self.view.height - paramSender.view.heigh /2 - 49, newCenter.y);
newCenter.x = MAX(paramSender.view.width/2, newCenter.x);
newCenter.x = MIN(self.view.width - paramSender.view.width/2, newCenter.x);
if(paramSender.state == UIGestureRecognizerStateChanged) {
paramSender.view.center = newCenter;
[paramSender setTranslation:CGPointMake(0, 0) inView:self.view];
}
if (paramSender.state == UIGestureRecognizerStateEnded) {
CGPoint tempPoint = newCenter;
if (newCenter.x < screenW/2.0) {
newCenter.x = paramSender.view.width/2;
} else {
newCenter.x = self.view.width- paramSender.view.width/2;
}
float seconds = ((fabs(tempPoint.x - newCenter.x))/screenW/2.0);
[UIView animateWithDuration:seconds animations:^{
paramSender.view.center = newCenter;
}];
}
}
网友评论