gpt4 book ai didi

iphone - 为什么 UIScrollView 不弹跳?

转载 作者:行者123 更新时间:2023-11-28 18:14:31 25 4
gpt4 key购买 nike

我这样做:

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

它可以很好地滚动,但 View 不会像预期的那样(?)反弹。

有什么想法吗?

最佳答案

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;

发现于:UIScrollView and its subclasses won't bounce if nested in custom UIView

关于iphone - 为什么 UIScrollView 不弹跳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6356693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com