Why is UIScrollView not bouncing?
I do this:
scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
[self addSubview:scrollView];
NSInteger x = scrollView.bounds.origin.x + Padding, y = scrollView.bounds.origin.y + Padding;
backButton = [[AButtonControl alloc] initWithCaption:@"Back" style:AButtonViewStyleGreen];
backButton.frame = CGRectMake(x, y, backButton.frame.size.width开发者_C百科, backButton.frame.size.height);
y += backButton.frame.size.height + Spacing;
[scrollView addSubview:backButton];
ownerNameTextField = [[AFormTextField alloc] initWithFrame:CGRectMake(x, y, 200, 60) label:@"Guest name"];
y += ownerNameTextField.frame.size.height + Spacing;
[scrollView addSubview:ownerNameTextField];
guestListSelectField = [[AFormSelectField alloc] initWithFrame:CGRectMake(x, y, 200, 60) label:@"Guest list"];
y += guestListSelectField.frame.size.height + Spacing;
[scrollView addSubview:guestListSelectField];
referenceUserSelectField = [[AFormSelectField alloc] initWithFrame:CGRectMake(x, y, 200, 60) label:@"Reference user"];
y += referenceUserSelectField.frame.size.height;
[scrollView addSubview:referenceUserSelectField];
scrollView.contentSize = CGSizeMake(self.bounds.size.width, y + Padding);
And it scrolls fine, but the view does not bounce like it is supposed(?) to.
Any ideas?
The underlying problem here is if you set the scrollview's frame/bounds in -layoutSubviews, it doesn't check if you're setting it to the frame/bounds that it already has, and this cancels the bounce. The solution is to do something like
CGFrame scrollFrame = [self calculateFrameForScrollView];
if (!CGRectEqualToRect(scrollFrame, self.myScrollView.frame))
self.myScrollView.frame = scrollFrame;
Found at: UIScrollView and its subclasses won't bounce if nested in custom UIView
精彩评论