UIScrollView content not allowing the user to interact

I have a UIScrollView with paging, for example:

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]; 

In UIScrollView, I will add some UIWebViews and set their interaction to yes like that.

 - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code self.frame = frame; self.userInteractionEnabled = YES; } return self; } 

which breaks the paging and everyone touches the UIScrollView. If I set the user interaction to NO, the page works, but I cannot select the text in the UIWebView. I tried to subclass UIScrollView as follows, but the same thing happens. 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]; } 
+7
source share
1 answer

Disabling user interaction with the container also effectively disables it in the subzones as well. You must enable it, causing the touch event to propagate through the view hierarchy;

 [container setUserInteractionEnabled:YES]; 

If you want to disable scrolling in a UIWebView, just go into its UIScrollView

 yourWebView.scrollView.scrollEnabled = NO; 

I tested this on my device and I can “scroll pages” in UIScrollView and select text in UIWebView.

EDIT:

I got this job! You must also enable touch undo:

 [container setCanCancelContentTouches:YES]; 
+10
source

All Articles