I have a UIScrollView with paging enabled like the following:
container = [[UIScrollView alloc] initWithFrame:kScrollViewFrame];
[container setDelegate:self];
[container setShowsHorizontalScrollIndicator:YES];
[container setShowsVerticalScrollIndicator:NO];
[container setClipsToBounds:YES];
[container setPagingEnabled:YES];
[container setDecelerationRate:UIScrollViewDecelerationRateFast];
[container setBounces:NO];
[container setUserInteractionEnabled:NO];
[container setCanCancelContentTouches:NO];
[container setDelaysContentTouches:NO];
To the UIScrollView, I add several UIWebViews, and set their interaction enabled to yes like so.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.frame = frame;
self.userInteractionEnabled = YES;
}
return self;
}
which breaks paging and all touches on the UIScrollView. If I set user interaction enabled to NO, page works, but I can't highlight text in the UIWebView. I tried subclassing UIScrollView like the following, but the same circumstances occur. Any idea?
- (id)initWithFrame:(CGRect)frame
{
NSLog(@"init");
return [super initWithFrame:frame];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan");
[[self nextResponder] touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesMoved");
[[self nextResponder] touchesMoved:touches withEvent:event];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesEnded");
[[self nextResponder] touchesEnded:touches withEvent:event];
}
Disabling user interaction on the container effectively disables it on the subviews as well. You should enable it, causing the touch event to propagate down the view hierarchy;
[container setUserInteractionEnabled:YES];
If you want to disable scrolling on the UIWebView just get inside its UIScrollView
yourWebView.scrollView.scrollEnabled = NO;
I've tested this on my device and I can both "page through" the UIScrollView and select text on UIWebView.
EDIT:
I got this working! You have to allow touch canceling as well:
[container setCanCancelContentTouches:YES];
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