在UITableView中观察捏合多点触摸手势 [英] Observing pinch multi-touch gestures in a UITableView

查看:151
本文介绍了在UITableView中观察捏合多点触摸手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在UITableView上实现一个缩进/缩小,我已经看了几个方法,包括这个:

I am looking to implement a pinch in/out on top of a UITableView, I have looked at several methods including this one:

类似问题

但是我可以创建一个 UIViewTouch 对象并将其覆盖到我的UITableView上,滚动事件没有被转发到我的UITableView,我仍然可以选择单元格,它们通过触发转换到新的ViewController对象来正确响应。但是我无法滚动UITableView,尽管传递了touchesBegan,touchesMoved和touchesEnded事件。

But while I can create a UIViewTouch object and overlay it onto my UITableView, scroll events are not being relayed to my UITableView, I can still select cells, and they respond properly by triggering a transition to a new ViewController object. But I can not scroll the UITableView despite passing the touchesBegan, touchesMoved, and touchesEnded events.

推荐答案

这似乎是一个经典问题。在我的情况下,我想拦截UIWebView上的一些事件,这些事件不能被子类化等等。

This seems to be a classic problem. In my case I wanted to intercept some events over a UIWebView which can't be subclassed, etc etc.

我发现最好的方法是使用UIWindow拦截事件:

I've found that the best way to do it is to intercept the events using the UIWindow:

EventInterceptWindow.h

EventInterceptWindow.h

@protocol EventInterceptWindowDelegate
- (BOOL)interceptEvent:(UIEvent *)event; // return YES if event handled
@end


@interface EventInterceptWindow : UIWindow {
    // It would appear that using the variable name 'delegate' in any UI Kit
    // subclass is a really bad idea because it can occlude the same name in a
    // superclass and silently break things like autorotation.
    id <EventInterceptWindowDelegate> eventInterceptDelegate;
}

@property(nonatomic, assign)
    id <EventInterceptWindowDelegate> eventInterceptDelegate;

@end

EventInterceptWindow.m:

EventInterceptWindow.m:

#import "EventInterceptWindow.h"

@implementation EventInterceptWindow

@synthesize eventInterceptDelegate;

- (void)sendEvent:(UIEvent *)event {
    if ([eventInterceptDelegate interceptEvent:event] == NO)
        [super sendEvent:event];
}

@end

创建该类,更改您的MainWindow.xib中的UIWindow类到EventInterceptWindow,然后在某处将eventInterceptDelegate设置为您想拦截事件的视图控制器。拦截双击的示例:

Create that class, change the class of your UIWindow in your MainWindow.xib to EventInterceptWindow, then somewhere set the eventInterceptDelegate to a view controller that you want to intercept events. Example that intercepts a double-tap:

- (BOOL)interceptEvent:(UIEvent *)event {
    NSSet *touches = [event allTouches];
    UITouch *oneTouch = [touches anyObject];
    UIView *touchView = [oneTouch view];
    //  NSLog(@"tap count = %d", [oneTouch tapCount]);
    // check for taps on the web view which really end up being dispatched to
    // a scroll view
    if (touchView && [touchView isDescendantOfView:webView]
            && touches && oneTouch.phase == UITouchPhaseBegan) {
        if ([oneTouch tapCount] == 2) {
            [self toggleScreenDecorations];
            return YES;
        }
    }   
    return NO;
}

此处的相关信息:
http://iphoneincubator.com/blog/windows-views/360idev-iphone-developers-conference-presentation

这篇关于在UITableView中观察捏合多点触摸手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆