[英]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, 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.
潜在的问题是,如果在-layoutSubviews中设置了滚动视图的框架/边界,它不会检查是否将其设置为它已经具有的框架/边界,这会取消反弹。 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 发现于: UIScrollView及其子类如果嵌套在自定义UIView中,则不会反弹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.