CGFloat
const gestureMinimumTranslation = 20.0;

typedef enum :NSInteger {

kCameraMoveDirectionNone,

kCameraMoveDirectionUp,

kCameraMoveDirectionDown,

kCameraMoveDirectionRight,

kCameraMoveDirectionLeft

} CameraMoveDirection;

@interfaceViewController ()

{

CameraMoveDirection direction;

}

@end

@implementation
ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];

[self.viewWithGestureRecognizer addGestureRecognizer:recognizer];

}

// This is my gesture recognizer handler, which detects movement in a particular

// direction, conceptually tells a camera to start moving in that direction

// and when the user lifts their finger off the screen, tells the camera to stop.

- (void)handleSwipe:(UIPanGestureRecognizer *)gesture

{

CGPoint translation = [gesture translationInView:self.view];

if (gesture.state ==UIGestureRecognizerStateBegan)

{

direction = kCameraMoveDirectionNone;

}

else
if (gesture.state == UIGestureRecognizerStateChanged && direction == kCameraMoveDirectionNone)

{

direction = [self determineCameraDirectionIfNeeded:translation];

// ok, now initiate movement in the direction indicated by the user's gesture

switch (direction) {

case kCameraMoveDirectionDown:

NSLog(@"Start moving down");

break;

case kCameraMoveDirectionUp:

NSLog(@"Start moving up");

break;

case kCameraMoveDirectionRight:

NSLog(@"Start moving right");

break;

case kCameraMoveDirectionLeft:

NSLog(@"Start moving left");

break;

default:

break;

}

}

elseif (gesture.state ==
UIGestureRecognizerStateEnded)

{

// now tell the camera to stop

NSLog(@"Stop");

}

}

// This method will determine whether the direction of the user's swipe

- (CameraMoveDirection)determineCameraDirectionIfNeeded:(CGPoint)translation

{

if (direction != kCameraMoveDirectionNone)

return direction;

// determine if horizontal swipe only if you meet some minimum velocity

if (fabs(translation.x) > gestureMinimumTranslation)

{

BOOL gestureHorizontal = NO;

if (translation.y ==0.0)

gestureHorizontal = YES;

else

gestureHorizontal = (fabs(translation.x / translation.y) >5.0);

if (gestureHorizontal)

{

if (translation.x >0.0)

return kCameraMoveDirectionRight;

else

return kCameraMoveDirectionLeft;

}

}

// determine if vertical swipe only if you meet some minimum velocity

else
if (fabs(translation.y) > gestureMinimumTranslation)

{

BOOL gestureVertical = NO;

if (translation.x ==0.0)

gestureVertical = YES;

else

gestureVertical = (fabs(translation.y / translation.x) >5.0);

if (gestureVertical)

{

if (translation.y >0.0)

return kCameraMoveDirectionDown;

else

return kCameraMoveDirectionUp;

}

}

return direction;

}

@end

最新文章

  1. Web测试中常见分享问题
  2. Android九宫格界面实现点击每个格点击跳转界面
  3. (转)ubuntu安装opengl
  4. [LeetCode] Combinations (bfs bad、dfs 递归 accept)
  5. Compound Interest Calculator1.0
  6. c笔记
  7. DFS+剪枝 HDOJ 5323 Solve this interesting problem
  8. 提高SQL查询效率的常用方法
  9. gcc将多个静态库链接成一个静态库
  10. Z - 不容易系列之(3)―― LELE的RPG难题
  11. Linux内核源代码解析之TCP面向字节流
  12. Memcached操作以及用法
  13. spring的aop详解
  14. js知识点记录
  15. mpvue——Error: Cannot find module 'escape-string-regexp'
  16. Ocelot中文文档-Configuration
  17. Win7系统的虚拟机中安装win7系统
  18. Beyond Compare 4提示已经过了30天试用期,破解方式,亲测可用
  19. DES、MD5、RSA加密算法
  20. 详解Oracle多种表连接方式

热门文章

  1. NYOJ 469 擅长排列的小明 II
  2. 九度oj 题目1140:八皇后
  3. ajax dome案例
  4. 关于IOS项目QQ空间授权提示安装最新版本的QQ的解决方法!
  5. cf287D Shifting
  6. android系统编译打开系统蓝牙
  7. POJ 1502 MPI Maelstrom [最短路 Dijkstra]
  8. msp430项目编程45
  9. Linux 环境下思源黑体字体与 Java 之间的兼容性问题的解决(补充说明)
  10. 模拟用户登录-SpringMVC+Spring+Mybatis整合小案例