本文介绍了如何阻止UIScrollView水平弹跳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIScrollView显示垂直数据,但水平分量不比iPhone的屏幕宽。问题是,用户仍然能够水平拖动,并且基本上暴露UI的空白部分。我已尝试设置:

I have a UIScrollView that shows vertical data, but where the horizontal component is no wider than the screen of the iPhone. The problem is that the user is still able to drag horizontally, and basically expose blank sections of the UI. I have tried setting:

scrollView.alwaysBounceHorizontal = NO;
scrollView.directionalLockEnabled = YES;

这有点帮助,但还是不能阻止用户水平拖动。确实有一种方法可以轻松解决这个问题?

Which helps a little, but still doesn't stop the user from being able to drag horizontally. Surely there is a way to fix this easily?

推荐答案

这很奇怪,因为每当我创建一个滚动视图框架和内容大小在任一维度的屏幕边界内,滚动视图不会在该方向上滚动(或反弹)。

That's strange, because whenever I create a scroll view with frame and content size within the bounds of the screen on either dimension, the scroll view does not scroll (or bounce) in that direction.

// Should scroll vertically but not horizontally
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scrollView.contentSize = CGSizeMake(320, 1000);

您确定框架完全适合屏幕,contentSize的宽度不大于滚动视图的宽度?

Are you sure the frame fits completely within the screen and contentSize's width is not greater than the scroll view's width?

这篇关于如何阻止UIScrollView水平弹跳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:37