将 UIView 拉伸到 UIScrollView 宽度
我有一个 UIView,我需要将其拉伸到 UIScrollView 的宽度。问题是下一个: 我需要拉伸该 UIView(即 EGOTableViewPullRefresh,只是一个自定义 UIView)。在视图初始化中,我放置了
[_refreshHeaderView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
。我尝试过:
-(void)scrollViewDidZoom:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidZoom");
[_refreshHeaderView setFrame:CGRectMake(0.0f, 0.0f - webScroller.bounds.size.height, webScroller.frame.size.width, webScroller.bounds.size.height)];
}
但它看起来就像图像一样。如果我进入 iOS 设计的页面(例如 Mobile Google),看起来没问题: 我怎样才能做到这一点?
I have a UIView
which I need to stretch to the width of a UIScrollView
. The problem is the next:
I'd need to stretch that UIView (which is EGOTableViewPullRefresh, just a custom UIView). In the view initialization I put [_refreshHeaderView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
. I tried:
-(void)scrollViewDidZoom:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidZoom");
[_refreshHeaderView setFrame:CGRectMake(0.0f, 0.0f - webScroller.bounds.size.height, webScroller.frame.size.width, webScroller.bounds.size.height)];
}
But it just looks as the image. If I enter to a iOS designed page (such as Mobile Google), it looks ok:
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIScrollView
的size.width
是设备上视图的宽度,而不是滚动视图内内容的宽度(即scrollView.contentSize .宽度
)。这意味着,如果“您的视图”位于 UIScrollView 之外,您确实需要滚动视图宽度,但如果您的视图位于滚动视图内部,则需要内容宽度。
请注意您提供的底部/Google 屏幕截图。注意到没有水平滚动了吗?在这种情况下,滚动视图内容大小宽度与滚动视图宽度相同,因此它可以完美工作。不过,上部/堆栈溢出图像确实有一个水平滚动条。所以滚动视图的内容宽度大于滚动视图的宽度。
简短回答:尝试将您的视图设置为
scrollView.contentSize.width
,而不是scrollView.frame.size.width
The
size.width
of aUIScrollView
is width of the view on your device, not the width of the contents inside the scroll view (which would bescrollView.contentSize.width
).This means, if "your view" is outside the
UIScrollView
you do want the scroll view width, but if your view is inside the scroll view you need the content width.Notice the bottom/Google screenshot you provided. Notice how there is no horizontal scrolling? In this case the scroll view contents size width is the same as the scroll view width so it works perfectly. The upper/stack overflow image does have a horizontal scroll bar though. So the content width of the scroll view is bigger than the scroll view width.
Short answer: Try setting your view to be the
scrollView.contentSize.width
, notscrollView.frame.size.width