简体   繁体   English

在UIScrollView的子视图中禁用水平滚动

[英]Disable horizontal scroll in a subview of UIScrollView

I have 3 UIScrollViews , call them A , B , and C . 我有3个UIScrollViews ,分别称为ABC

A is a Paging scrollview, that has many B scrollviews added as subviews (the pages). A是一个分页滚动视图,其中添加了许多B滚动视图作为子视图(页面)。 B only scrolls vertically. B仅垂直滚动。 C is a scrollview added as a subview to a UIView that is added as a subview to B . C是作为子视图添加到UIView的滚动视图,而UIView是作为B子视图添加的。

The functionality I am trying to achieve is: 我想要实现的功能是:

Disallow paging of A if a horizontal scroll is happening within the UIView that is housing C . 如果在容纳CUIView中发生水平滚动,则不允许分页A However, still allow the vertically scrolling of B . 但是,仍然允许B的垂直滚动。

Implement the - (void)scrollViewDidScroll:(UIScrollView*)scrollView to find out which scrollview is scrolling and then check contentOffset property of scrollview to determine the scrolling position of scrollviews. 实现- (void)scrollViewDidScroll:(UIScrollView*)scrollView可以找出正在滚动的滚动视图,然后检查scrollview的contentOffset属性以确定滚动视图的滚动位置。 scrollViewDidEndDecelerating delegate can be used to detect the end of scrolling. scrollViewDidEndDecelerating委托可用于检测滚动结束。

for eg:- 例如:

- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
    if (scrollView == C) {
       //disable scrolling of A
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (scrollView == C) {
        //enable scrolling of A
    }
}

Based on your exact requirement, you can use these two delegates and contentOffset of that particular scrollview to get the desired effect. 根据您的确切要求,可以使用这两个委托和该特定scrollview的contentOffset来获得所需的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何禁用UIScrollView的特定子视图中的滚动 - How to disable scroll in a specific subview of a UIScrollView 禁用 UIScrollView 水平滚动的最佳方法是什么? - What is the best way to disable horizontal scroll of UIScrollView? UIScrollView水平滚动-禁用向左滚动 - UIScrollView Horizontal scrolling - Disable left scroll 带有水平分页的UIScrollView不会使子视图居中 - UIScrollView with horizontal paging` does not center subview UIScrollView子视图中的水平UISwipeGestureRecognizer? (UIScrollView只需要识别垂直滚动) - Horizontal UISwipeGestureRecognizer in subview of UIScrollView ? (UIScrollView only needs to recognize vertical scrolling) 如何禁用 UIScrollView 的水平滚动? - How to disable horizontal scrolling of UIScrollView? 为什么我的UIScrollView水平滚动条没有显示? - Why is my UIScrollView horizontal scroll bar not showing? 根据屏幕适合子视图并在IOS中禁用滚动 - Fit subview according to screen and disable scroll in IOS 如何以编程方式滚动UIScrollView,它是自定义UITableViewCell的子视图? - How to scroll UIScrollView programmatically which is a subview of the custom UITableViewCell? ios-charts子视图上拖动时,uiscrollview不会滚动 - uiscrollview won't scroll when dragging on ios-charts subview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM