垂直滚动视图中水平滚动查看不起作用

问题描述 投票:3回答:2

伙计们!我有一个UIScrollView(主滚动视图),我想仅垂直滚动。里面吧,我还有的UIScrollView(孩子滚动视图),它只能横向滚动。在孩子滚动视图我有两个看法。这里是一个图片说明。我的问题是,孩子滚动视图没有水平滚动。

我使用自动布局,但也试图与:

[self.innerScrollView setDelegate:self];
[self.innerScrollView setScrollEnabled:YES];
self.innerScrollView.pagingEnabled = YES;
self.innerScrollView.contentSize = CGSizeMake(640, 300);

我也试图与继承自UIScrollView的两个滚动视图的使用:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

我在这一点上有点无能,所以任何输入将不胜感激。

ios uiscrollview
2个回答
3
投票

让你内心的滚动视图帧的宽度320

为了使您的滚动视图滚动水平化妆的contentSize宽度大于它的边框宽度


0
投票

在新版iOS我要实现手动的逻辑来实现这一目标。

如果我想在父滚动视图垂直滚动,而我的水平滚动这是嵌套在孩子滚动视图,我不得不启用UIScrollView的委托,以我目前的类对孩子滚动视图,然后使用我创建了以下逻辑:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {

    if (scrollView == childScrollView) {
        static float lastOffsetY;
        float currentOffsetY = [scrollView.panGestureRecognizer translationInView:scrollView.superview].y;
        if (scrollView.panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
            lastOffsetY = currentOffsetY;
        } else {
            float dy = currentOffsetY-lastOffsetY;
            [UIView animateWithDuration:0.1f
                                  delay:0.0f
                                options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState)
                             animations:^(void) {
                                 [parentScrollView setContentOffset:CGPointMake(parentScrollView.contentOffset.x,
                                                                          parentScrollView.contentOffset.y-dy)
                                                     animated:NO];
                             }
                             completion:^(BOOL finished) {

                             }];
        }
        lastOffsetY = currentOffsetY;
    }

}
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {

    if (scrollView == childScrollView) {
        float oy = parentScrollView.contentOffset.y;
        float noy = oy;
        if (oy < 0) {
            noy = 0;
        }
        if (oy > parentScrollView.contentSize.height-parentScrollView.frame.size.height) {
            noy = parentScrollView.contentSize.height-parentScrollView.frame.size.height;
        }
        if (noy != oy) {
            [UIView animateWithDuration:0.1f
                                  delay:0.0f
                                options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState)
                             animations:^(void) {
                                 [parentScrollView setContentOffset:CGPointMake(parentScrollView.contentOffset.x,
                                                                          noy)
                                                     animated:NO];
                             }
                             completion:^(BOOL finished) {

                             }];
        }
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.