在我的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