我正在寻找在 UITableView 之上实现捏入/捏出,我已经研究了几种方法,包括这个:
类似问题
但是虽然我可以创建一个UIViewTouch
对象并将其覆盖到我的 UITableView 上,滚动事件不会转发到我的 UITableView,我仍然可以选择单元格,并且它们通过触发到新 ViewController 对象的转换来正确响应。但尽管传递了touchesBegan、touchesMoved 和touchesEnded 事件,我仍无法滚动UITableView。
这似乎是一个经典问题。就我而言,我想通过 UIWebView 拦截一些无法子类化的事件,等等。
我发现最好的方法是使用 UIWindow 拦截事件:
事件拦截窗口.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
事件拦截窗口.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 设置为要拦截事件的视图控制器。拦截双击的示例:
- (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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)