当时我就震惊了移动开发iOS Developer

关于手势处理

2016-09-13  本文已影响76人  海泉

项目要求:通过手势滑动方向和距离操作无人机

起初

用UISwipeGestureRecognizer初始化,指定四个方向direction,再添加到views 上,啪啪啪,三两下搞好了,发现swipe是在UIGestureRecognizerStateEnded状态下才触发的,而不能获得 UIGestureRecognizerStateBegan

而要求是要在滑动过程中,持续将发出数据,

现在

不使用系统手势,直接获取view的点击事件

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event;

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event;

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event;

在方法中有做判断

if([touches count] != 1)

return ;

UITouch *touch = [touches anyObject];

UIView *view = [touch view];

if(view != self)

return ;

Point = [touch locationInView:view];

然后在Began时获得起始点 startPoint,并开启定时器 [self startUpdateTimer],在Moved时获得结束点 endPoint,在Ended中关闭定时器 [self stopUpdateTimer];将两者的距离和方向计算出来

- (void)distanceOfPoint:(CGPoint)point1 withPoint:(CGPoint)point2

内部计算较为简单,然后将滑动方向和距离 结果传出,这里用了刚学到的新技能RAC,将信号压缩传出

[[RACSignal zip:@[self.directionSignal, self.distanceandSignal, self.viewTargetSignal]]subscribeNext:^(id x) {

NSDictionary *flyOrderInfo = [NSDictionary dictionaryWithObjectsAndKeys:

x, @"flyOrderInfo", nil];

postNotification(SENDFLYORDER,self, flyOrderInfo);

}];

上一篇下一篇

猜你喜欢

热点阅读