简体   繁体   English

iOS 9:如何使滚动条底部的内容视图固定在scrollview底部?

[英]iOS 9 : how to make the content view of a scroll bar bottom stick to the scrollview bottom?

I have a UIScrollView whose backgroundColor is UIColor.clearColor(). 我有一个UIScrollView,其backgroundColor为UIColor.clearColor()。 That scroll view's content view has background color red and take advantage of the standard bouncing feature. 该滚动视图的内容视图具有红色的背景色,并利用了标准的反弹功能。

But when I scroll it upwards, when the scroll exceeds the contentSize height, the underlying views appears (reminding you the scroll background being clear color). 但是,当我向上滚动时,当滚动超过contentSize高度时,将显示基础视图(提醒您滚动背景为清晰的颜色)。 See the image: 见图片:

在此处输入图片说明

My code is quite standard: 我的代码很标准:

    scrollView.delegate           = self
    scrollView.backgroundColor    = UIColor.clearColor()
    scrollView.contentSize        = view.frame.size

    view.addSubview(scrollView)

I'd keep it simple and just add another view behind the scroll view at the bottom of the screen, probably about half the height of the view, and the same colour as the background. 我会保持简单,只是在屏幕底部的滚动视图后面添加另一个视图,可能大约是视图高度的一半,并且与背景颜色相同。 So, when you scroll the content up you just see through to that view instead of the content behind. 因此,当您向上滚动内容时,您只会看到该视图,而不是后面的内容。

You could turn bouncing on and off depending on the scroll direction but you'd get little UI glitches. 您可以根据滚动方向打开和关闭弹跳功能,但UI出现小故障。 You could add a delegate for the scroll gesture recogniser and use gestureRecognizer:shouldReceiveTouch: but you could end up with similar UI issues. 您可以为滚动手势识别器添加一个委托,并使用gestureRecognizer:shouldReceiveTouch:但最终可能会gestureRecognizer:shouldReceiveTouch:类似的UI问题。

Add a UIView into your scrollView with the same color as your content background color. UIView添加到您的scrollView ,其颜色与内容背景色相同。 Set its frame so its outside the scrollView.contentSize (ie: y < 0 at the top, y > contentSize.height at the bottom). 设置其frame ,使其位于scrollView.contentSize之外(即: y < 0在顶部, y > contentSize.height在底部)。 Make it big enough to cover the bounce gap. 使其足够大以弥补反弹间隙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM