我这样做:
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, 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);
它滚动得很好,但视图不像它应该(?)那样反弹。
有什么想法吗?
答案 0 :(得分:7)
这里的根本问题是如果你在-layoutSubviews中设置scrollview的frame / bounds,它不会检查你是否将它设置为它已经拥有的帧/边界,这会取消反弹。解决方案是做类似
的事情
CGFrame scrollFrame = [self calculateFrameForScrollView];
if (!CGRectEqualToRect(scrollFrame, self.myScrollView.frame))
self.myScrollView.frame = scrollFrame;
发现于:UIScrollView and its subclasses won't bounce if nested in custom UIView