2011-08-20 124 views
3

我覆盖了子类,它拒绝调用touchesShouldCancelInContentView。我发誓我已经写了代码来做到这一点。我正在覆盖该类,以便某些视图不会将触摸事件传递到滚动视图。touchesShouldCancelInContentView不被称为

随着类

@interface SlidingWindowScrollView : UIScrollView 
{ 
    UIView* noTouchView; 
} 

@property (nonatomic, retain) UIView* noTouchView; 
@end 

和实现

@implementation SlidingWindowScrollView 
@synthesize noTouchView; 

- (BOOL)touchesShouldCancelInContentView:(UIView *)view 
{ 
    BOOL shouldCancel = NO; 
    if(view == noTouchView) 
     shouldCancel = YES; 

    NSLog(@"shouldCancel %d", shouldCancel); 
    return shouldCancel; 
} 
@end 

在我扔下一个滚动视图和里面一个UIView,写这在VC视图做负载的厦门国际银行。

scrollView.contentSize = CGSizeMake(scrollView.bounds.size.width*2, 
            scrollView.bounds.size.height); 
scrollView.pagingEnabled = YES; 
scrollView.canCancelContentTouches = YES; 

contentView.frame = CGRectMake(scrollView.frame.size.width + 20, 
           0, 
           scrollView.frame.size.width, 
           scrollView.frame.size.height); 
contentView.userInteractionEnabled = YES; 
scrollView.noTouchView = contentView; 
[scrollView setContentOffset:CGPointMake(scrollView.bounds.size.width, 0) animated:YES]; 

我不知道给了什么。这应该是一个简单的覆盖。我确信XIB中的自定义类是正确的,并且网点都表示它是我的UIScrollView的新子类。我不是故意放肆但在最新的iOS API中做了些什么?这看起来应该很容易,但它从来没有调用touchesShouldCancelInContentView函数。我很困惑。我非常感谢有人可以证明我错了,并得到这个函数被scrollView调用。我想应该注意的是,打印语句确实打印出来了,但它可以始终如一地完成

如果你能在你的机器上正常工作,请让我知道,因为我没有看到任何错误。这让我疯狂@ _ @希望有人能帮助我。谢谢。

+0

我想应该指出,我试图覆盖touchesBegan成功和touchesShouldBegin的作品,但它只触发时触摸释放这是违背文档说什么是“被子类覆盖自定义默认行为时手指触摸向下显示的内容。“ – Biclops

+0

也在模拟器中运行,仅供参考。 – Biclops

回答

13

从我所看到的东西,你没有得到touchesShouldCancelInContentView:或touchesShouldBegin:withEvent:方法inContentView:回调,除非你有delaysContentTouches设置为NO:

scrollView.delaysContentTouches = NO; 
+9

虽然,我给delayedContentTouches'NO'仍然touchesshouldcancelincontentview没有被调用 – Femina

+0

为我工作!文档中没有很好的记录。谢谢澄清! –

4

我就死在这一段时间柜面你读过这一点,你需要有既touchesShouldCancelInContentView接触之前设置以下属性将火

scrollView.delaysContentTouches = NO; 

scrollView.canCancelContentTouches = YES; 

只要有scrollView.delaysContentTouches = NO不会火,如果scrollView.canCancelContentTouches = NO

+0

很高兴知道我会试试这个,如果我回到这个代码。谢谢。 – Biclops