views:

28

answers:

1

Hello all

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

A: 

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.

Jack