2011-05-24 68 views
0

我用这个代码来检测上的UIScrollView谁是UIView的UIScrollView的子类来检测触摸不灵

.h文件中

@interface AppScrollView : UIScrollView 
{ 
} 

@end 

.m文件

的顶部触摸
#import "AppScrollView.h" 

@implementation AppScrollView 

- (id)initWithFrame:(CGRect)frame 
{ 
    return [super initWithFrame:frame]; 
} 

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event 
{ 
    // If not dragging, send event to next responder 
    if (!self.dragging) 
    [self.nextResponder touchesEnded: touches withEvent:event]; 
    else 
    [super touchesEnded: touches withEvent: event]; 
} 

@end 

然后在另一个班级我加

#import <UIKit/UIKit.h> 

@class AppScrollView; 

@interface SomeClass : UIViewController <UIScrollViewDelegate> 
{ 
    AppScrollView *scrollView; 
    ... 
} 

@end 

#import "AppScrollView.h" 

@implementation SomeClass 

... 

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event 
{ 
    // Process the single tap here 
    ... 
} 

... 

@end 

我也用过scroll1.delegate=self;但没有任何反应!

任何人都可以帮助我吗?

+0

您是否仅创建子类来检测触摸? – 2011-05-24 15:14:21

+0

是的,这是为什么我实现了子类 – stefanosn 2011-05-24 16:35:03

回答