【问题标题】:iPhone - Gestures on UIPickerView and UIWebViewiPhone - UIPickerView 和 UIWebView 上的手势
【发布时间】:2010-02-14 08:03:56
【问题描述】:

我正在制作一个 iPhone 应用程序,用户可以在其中做手势(左右滑动)来浏览标签。我的问题是某些页面具有诸如pickerview、webview、文本字段和按钮之类的视图。滑动不适用于这些。有没有办法拥有全局手势?

作为参考,我的手势代码示例:

//Swipe between tabs
#define mindrag 100
CGPoint mystartTouchPosition;
BOOL isProcessingListMove;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint newTouchPosition = [touch locationInView:self.view];
    if(mystartTouchPosition.x != newTouchPosition.x || mystartTouchPosition.y != newTouchPosition.y) {
        isProcessingListMove = NO;
    }
    mystartTouchPosition = [touch locationInView:self.view];
    [super touchesBegan:touches withEvent:event];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = touches.anyObject;
    CGPoint currentTouchPosition = [touch locationInView:self.view];

    // If the swipe tracks correctly.
    double diffx = mystartTouchPosition.x - currentTouchPosition.x + 0.1; // adding 0.1 to avoid division by zero
    double diffy = mystartTouchPosition.y - currentTouchPosition.y + 0.1; // adding 0.1 to avoid division by zero

    if(abs(diffx / diffy) > 2.5 && abs(diffx) > mindrag)
    {
        // It appears to be a swipe.
        if(isProcessingListMove) {
            // ignore move, we're currently processing the swipe
            return;
        }

        if (mystartTouchPosition.x < currentTouchPosition.x) {
            isProcessingListMove = YES;
            self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
            return;
        }
        else {
            isProcessingListMove = YES;

            self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:3];

            return;
        }
    }
    else if(abs(diffy / diffx) > 1)
    {
        isProcessingListMove = YES;
        [super touchesMoved:touches withEvent:event];
    }
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
    isProcessingListMove = NO;
    [super touchesEnded:touches withEvent:event];
}
// End of swipe

感谢任何输入。

【问题讨论】:

    标签: iphone sdk uiwebview uipickerview gesture


    【解决方案1】:

    您可以继承 UIImagePickerControllerUIWebView 并将这些手势捕获视图添加到它们,只要您的手势检测当然仍然可以将触摸传递给底层视图。

    【讨论】:

    • UIImagePickerController 是一个具有view 属性的控制器。而UIWebView 继承自UIView
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 2012-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多