在我的iOS应用程序,我有以下设置:UISwipeGestureRecognizer @selector不会被调用,因为UIPanGestureRecognizer设立
- (void)setupGestures
{
UIPanGestureRecognizer* panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
[self.view addGestureRecognizer:panRecognizer];
UISwipeGestureRecognizer* swipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
[swipeUpRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
[self.view addGestureRecognizer:swipeUpRecognizer];
}
// then I have following implementation of selectors
// this method supposed to give me the length of the swipe
- (void)panGesture:(UIPanGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan)
{
startLocation = [sender locationInView:self.view];
}
else if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint stopLocation = [sender locationInView:self.view];
CGFloat dx = stopLocation.x - startLocation.x;
CGFloat dy = stopLocation.y - startLocation.y;
CGFloat distance = sqrt(dx*dx + dy*dy);
NSLog(@"Distance: %f", distance);
}
}
// this method does all other actions related to swipes
- (void)handleSwipe:(UISwipeGestureRecognizer *)gestureRecognizer
{
UISwipeGestureRecognizerDirection direction = [gestureRecognizer direction];
CGPoint touchLocation = [gestureRecognizer locationInView:playerLayerView];
if (direction == UISwipeGestureRecognizerDirectionDown && touchLocation.y > (playerLayerView.frame.size.height * .5))
{
if (![toolbar isHidden])
{
if (selectedSegmentIndex != UISegmentedControlNoSegment)
{
[self dismissBottomPanel];
}
else
{
[self dismissToolbar];
}
}
}
}
所以问题是,handleSwipe是从来没有得到所谓的...当我注释掉UIPanGestureRecognizer设置,handleSwipe开始工作。
我很新手势识别编程,所以我假设我在这里失去了一些基本的东西。
任何形式的帮助,高度赞赏!
附注 - 为什么要调用'allocWithZone:nil'?只需调用'alloc'。 – rmaddy
当然......但这并不影响我的问题,对吧? :) –
完全没有,这就是为什么我用“旁注”作为前缀。 :) – rmaddy