UIPanGestureRecognizer使用小结(3)
来源:未知 责任编辑:责任编辑 发表时间:2014-02-18 03:21 点击:次
p> NSLog(@"pan gesture testPanView begin is %@,%@", NSStringFromCGPoint([recognizer view].center), NSStringFromCGRect([recognizer view].frame));
p> }
p>
p> if ([(UIPanGestureRecognizer *)recognizer state] == UIGestureRecognizerStateChanged) {
p> CGFloat x = firstX + translatedPoint.x;
p> CGFloat y = firstX + translatedPoint.y;
p>
p> if (x < recognizer.view.width / 2.0) {
p> x = recognizer.view.width / 2.0;
p> } else if (x + recognizer.view.width / 2.0 > self.view.width) {
p> x = self.view.width - recognizer.view.width / 2.0;
p> }
p>
p> if (y < recognizer.view.height / 2.0) {
p> y = recognizer.view.height / 2.0;
p> } else if (y + recognizer.view.height / 2.0 > self.view.height) {
p> y = self.view.height - recognizer.view.height / 2.0;
p> }
p>
p> NSLog(@"gesture translatedPoint moving is %@", NSStringFromCGPoint(translatedPoint));
p>
p> recognizer.view.center = CGPointMake(x, y);
p> }
p>
p> if (([(UIPanGestureRecognizer *)recognizer state] == UIGestureRecognizerStateEnded) || ([(UIPanGestureRecognizer *)recognizer state] == UIGestureRecognizerStateCancelled)) {
p> CGFloat x = recognizer.view.center.x;
p> CGFloat y = recognizer.view.center.y;
p>
p> if (x > firstX) {
p> x = self.view.width - recognizer.view.width / 2.0;
p> } else {
p> x = recognizer.view.width / 2.0;
p> }
p>
p> if (y > firstY) {
p> y = self.view.height - recognizer.view.height / 2.0;
p> } else {
p> y = recognizer.view.height / 2.0;
p> }
p>
p> CGFloat velocityX = (0.2 *[recognizer velocityInView:self.view].x);
p>
p> [UIView beginAnimations:nil context:NULL];
p>
p> [UIView setAnimationDuration:ABS(velocityX * 0.00002 + 0.2)];
p>
p> [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
p>
p> recognizer.view.center = CGPointMake(x, y);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>