iphone - 观察 UITableView 中的捏合多点触控手势

标签 iphone uitableview multi-touch pinch

我正在寻找在 UITableView 顶部实现捏入/捏出,我已经研究了几种方法,包括这个:

Similar question

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

最佳答案

这似乎是一个经典问题。就我而言,我想通过 UIWebView 拦截一些无法子类化的事件,等等。

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

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:

#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 设置为要拦截事件的 View Controller 。拦截双击的示例:

- (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

关于iphone - 观察 UITableView 中的捏合多点触控手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2003201/

相关文章:

iphone - 在 textView 中,当我点击完成按钮时,键盘没有退出

swift - 表解析查询不出现

iphone - 简单的核心数据获取非常慢

iphone - CGPDF iPhone/iPad 内存问题

iphone - 更改 UITableView 以清除颜色

dart - 如何使用 flutter 在移动应用程序中禁用多点触控

ios - 如何在设备上的每个触摸位置周围绘制一个圆圈?

android - 我们如何在android中创建多点触控?

iPhone EKEvent Availability,我尝试设置它,但它不会改变

ios - 如何以编程方式将搜索栏添加到 UITableView header ?