UIScrollView(分页模式)只有在有两个或更多页面时才弹跳?

发布于 2024-09-24 00:16:39 字数 850 浏览 2 评论 0原文

我只是有这个奇怪的问题。我有一个 UIScrollView,并且该滚动中只有一页。滚动启用分页并启用弹跳。

这是我的代码(在 iPad 中),

scroll = [[UIScrollView alloc] init];
scroll.pagingEnabled = YES;
scroll.showsHorizontalScrollIndicator = NO;
scroll.showsVerticalScrollIndicator = NO;
scroll.scrollsToTop = NO;
scroll.bounces = YES;
scroll.delegate = self;
CGRect frame = CGRectMake(0.0, 0.0, 768, 1004);
scroll.frame = frame;
[self.view addSubview:scroll];


UIView *view1 = [[UIView alloc] init];
view1.frame = CGRectMake(0, 0.0, 768, 1004);
view1.clipsToBounds = YES;
view1.backgroundColor = [UIColor redColor];
[scroll addSubview:view1];


scroll.contentSize = CGSizeMake(768 * 1, 1004);

非常简单。我只是创建一个 UIView,并将其添加到滚动。并将滚动条的 contentSize 设置为仅容纳一个视图。

但我运行后,滚动根本不反弹。

如果我添加第二个视图并设置滚动的 contentSize 双宽度,它会弹跳。

我想知道如果只有一页滚动是否永远不会弹跳?

谢谢

I just have this strange question. I have a UIScrollView, and I have only one page in that scroll. The scroll is paging enabled and bounce enabled.

Here is my code (in iPad)

scroll = [[UIScrollView alloc] init];
scroll.pagingEnabled = YES;
scroll.showsHorizontalScrollIndicator = NO;
scroll.showsVerticalScrollIndicator = NO;
scroll.scrollsToTop = NO;
scroll.bounces = YES;
scroll.delegate = self;
CGRect frame = CGRectMake(0.0, 0.0, 768, 1004);
scroll.frame = frame;
[self.view addSubview:scroll];


UIView *view1 = [[UIView alloc] init];
view1.frame = CGRectMake(0, 0.0, 768, 1004);
view1.clipsToBounds = YES;
view1.backgroundColor = [UIColor redColor];
[scroll addSubview:view1];


scroll.contentSize = CGSizeMake(768 * 1, 1004);

It is very simple. I just create one UIView, and add it to scroll. And set the scroll's contentSize to hold exact one view.

But after I run it, scroll does not bounce at all.

If I add 2nd View and set scroll's contentSize double Width, it bounces.

I am wondering whether scroll will never bounce if only one page in?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

手心的温暖 2024-10-01 00:16:39

你可以使用属性:

scroll.alwaysBounceHorizontal= YES;

 scroll.alwaysBounceVertical = YES;

或两者都

不要添加1px,如果你在滚动视图内的UIView中添加可触摸元素,它会给你带来问题。

重新定义滚动框架后,永远不要忘记再次定义您的 contentSize。即使 contentSize 也保持相同的值。

祝你好运

you can use the property :

scroll.alwaysBounceHorizontal= YES;

or

 scroll.alwaysBounceVertical = YES;

or both

Don't add 1px, it will create problems to you if you add touchable elements in the UIView inside your scrollview.

Never forget to define again your contentSize after redefine the frame of your scroll. even the contentSize keep the same value.

Good luck

狼亦尘 2024-10-01 00:16:39

回答我自己。

如果你希望 UIScrollView 能够弹起,你应该将其 contentSize 设置为大于其框架大小。

即使大1px对于我自己的代码来说也足够了

如果我设置scroll.contentSize = CGSizeMake(768 * 1 + 1, 1004);, 。它会工作并弹跳。

answer myself.

If you want UIScrollView to be able to bounce, you should set its contentSize bigger than its frame size.

Even 1px bigger is enough

for my own code, if I set scroll.contentSize = CGSizeMake(768 * 1 + 1, 1004); it will work and bounce.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文