UIScrollView(分页模式)只有在有两个或更多页面时才会弹跳? [英] UIScrollView (paging mode) bounces only when there two or more pages?

查看:124
本文介绍了UIScrollView(分页模式)只有在有两个或更多页面时才会弹跳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是有这个奇怪的问题。我有一个UIScrollView,我在该滚动中只有一个页面。滚动页面启用了分页并启用了退回。

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.

这是我的代码(在iPad中)

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);

这很简单。我只创建一个UIView,并将其添加到滚动。并设置滚动的contentSize以保存完全一个视图。

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.

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

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?

谢谢

推荐答案

您可以使用该属性:

scroll.alwaysBounceHorizontal= YES;

 scroll.alwaysBounceVertical = YES;

或两者

不要添加1px的,如果添加在您的滚动视图里面的UIView可触摸的元素会产生问题给你。

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

不要忘记重新定义你的contentSize重新定义您的滚动的框架之后。甚至contentSize保持相同的价值。

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

祝你好运

这篇关于UIScrollView(分页模式)只有在有两个或更多页面时才会弹跳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆