Reputation: 1686
I've read the various threads on this but none have given me the exact solution I need, but they have got me pretty close
I have the topmost UIViewController which contains a paging UIScrollingView (created via the xib)
The UIScrollingView loads an array of dummy viewcontrollers which are swapped for various viewControllers as the user swipes through the pages.
One of these subviews contains a bunch of sliders - the usual problem: if the user misses a slider slightly they scroll the page instead.
Within the subview I placed a UIView behind the sliders partially covering the screen: 'uiviewblocker'
The idea is that this 'uiviewblocker' eats any touches in the immediate area around the sliders, but swipes outside the uiview are handled by the parent UIViewController. I subclassed the UIView 'uiviewblocker' to a duplicate UIViewController 'MyView' so I can detect it.
I've got as far as...
The parent UIScrollView:
scrollView.delaysContentTouches = NO;
The subview UIViewController
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
NSLog(@"touchesBegan");
//[self.nextResponder touchesBegan: touches withEvent:event];
UIView *touchView = [[touches anyObject] view];
if ([touchView isKindOfClass:[MyView class]]) {
NSLog(@"funky shit");
[super touchesBegan:touches withEvent:event];
//[self.delegate touchesBegan:touches withEvent:event];
//[self touchesBegain:touches withEvent:event]; // View does not respond: crashes
//UIView *parent = self.view.superview;
//[parent setCanCancelContentTouches:YES]; // UIView does not respond
//UIScrollView * parentScrollView = (UIScrollView*)self.superview; // Superview not in structure
} else {
NSLog(@"normal shit");
}
}
So now I can detect when the user is touching the safety area UIview by testing for it's class 'MyView' but I can't work out how to either tell the parent UIScrollView to abort or just the touch there and then
Upvotes: 2
Views: 806
Reputation: 2537
I had a similar problem with my app. Scroll view contained a subview, which contained its own subview. When the sub-sub view appeared, the scrollview needed to not be able to scroll. I incorporated notifications by posting them from the sub-sub view and listening for them in the scroll view controller. I've posted all the code on my thread here: https://stackoverflow.com/a/9010117/1007725
I know it's been a few months since you went with the invisible button technique, but in case you were still looking for a coding way to accomplish it, or anyone else finds this thread, I thought I'd share. If you'd like help translating my code to yours, just let me know and I'll do the best I can.
Upvotes: 0
Reputation: 1296
Put a transparent UIButton behind the UISlider. The button will "eat" the touches and prevent scrolling.
Upvotes: 1