I've overwritten the subclass and it refuses to be call touchesShouldCancelInContentView. I swear I've written code to do this before. I'm overwriting the class so that certain views don't pass along the touch events to the scroll view.
With the class
@interface SlidingWindowScrollView : UIScrollView
{
UIView* noTouchView;
}
@property (nonatomic, retain) UIView* noTouchView;
@end
And the implementation
@implementation SlidingWindowScrollView
@synthesize noTouchView;
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
BOOL shouldCancel = NO;
if(view == noTouchView)
shouldCancel = YES;
NSLog(@"shouldCancel %d", shouldCancel);
return shouldCancel;
}
@end
In the xib I throw down a scrollview and a uiview inside it and write this in the VC view did load.
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];
I don't know what gives. This should be a simple override. I made sure that the custom class was correct in the XIB and that the outlets all said it was my new subclass of UIScrollView. I don't mean to be presumptuous but did something break in the newest iOS API? This seems like it should be easy yet it never calls the function touchesShouldCancelInContentView. I'm baffled. I'd greatly appreciate it someone could prove me wrong and get this function to be called by the scrollView. I suppose it should be noted that the print statement did print but it could be consistently done
If you can get this working on your machine please let me know, because I don't see anything wrong. It's driving me nuts @_@ Hope someone can help me out. Thanks.
From what I've seen, you don't get touchesShouldCancelInContentView: or touchesShouldBegin:withEvent:inContentView: callbacks unless you have delaysContentTouches set to NO:
scrollView.delaysContentTouches = NO;
I got stuck on this for a while incase you ever read this, you need to have both the following properties set before touches in touchesShouldCancelInContentView
will fire
scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;
Just having scrollView.delaysContentTouches = NO
wont fire if scrollView.canCancelContentTouches = NO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With