UIScrollView 中较小的 UIView 以停止触摸
我已经阅读了有关此问题的各种线程,但没有一个给我提供了我需要的确切解决方案,但它们已经让我非常接近了
我有最上面的 UIViewController,其中包含分页 UIScrollingView (通过 xib 创建)
UIScrollingView 加载一个虚拟数组当用户滑动页面时,视图控制器会交换为各种视图控制器。
其中一个子视图包含一堆滑块 - 这是常见的问题:如果用户稍微错过了滑块,他们就会滚动页面。
在子视图中,我在部分覆盖屏幕的滑块后面放置了一个 UIView: 'uiviewblocker'
这个想法是,这个 'uiviewblocker' 会吃掉滑块周围直接区域中的任何触摸,但在 uiview 之外的滑动由父 UIViewController 处理。我将 UIView 'uiviewblocker' 子类化为重复的 UIViewController 'MyView',以便我可以检测到它。
我已经得到了...
父 UIScrollView:
scrollView.delaysContentTouches = NO;
子视图 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");
}
}
所以现在我可以通过测试它的类“MyView”来检测用户何时触摸安全区域 UIview 但我不知道如何告诉父 UIScrollView 中止或只是触摸那里然后
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 UISlider 后面放置一个透明的 UIButton。该按钮将“吃掉”触摸并阻止滚动。
Put a transparent UIButton behind the UISlider. The button will "eat" the touches and prevent scrolling.
我的应用程序也有类似的问题。滚动视图包含一个子视图,该子视图包含它自己的子视图。当子子视图出现时,滚动视图需要不能滚动。我通过从子子视图发布通知并在滚动视图控制器中监听通知来合并通知。我已将所有代码发布在我的线程上: https://stackoverflow.com/a/9010117/1007725
我我知道自从您使用隐形按钮技术以来已经有几个月了,但是如果您仍在寻找一种编码方法来完成它,或者其他人找到了这个线程,我想我会分享。如果您需要帮助将我的代码翻译为您的代码,请告诉我,我会尽力而为。
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.