简体   繁体   English

UIScrollView滚动条的宽度和高度?

[英]UIScrollView scrollbar width and height?

Is there a way to reference the width and height of the scrollbars in a UIScrollView? 有没有一种方法可以引用UIScrollView中滚动条的宽度和高度? I see content size and content offset, but neither seems like it will help. 我看到了内容大小和内容偏移,但似乎都没有用。

TL;DR TL; DR
To keep track of the lowest Y position of the views I've added to a UIScrollView , I use: 为了跟踪添加到UIScrollView的视图的最低Y位置,我使用:

lowestView = scrollView.subviews.sorted(by: { $0.frame.maxY < $1.frame.maxY }).last?.frame.maxY ?? 0

But this doesn't take into account the fact that a UIScrollView already includes two subviews for the scrollbars - which, of course, messes up the above calculation. 但这并没有考虑到UIScrollView已经包括滚动条的两个子视图的事实-当然,这会弄乱上面的计算。

What I'd really like to do is filter the scrollbars from the subview. 我真正想做的是从子视图中过滤滚动条。 Which would look something like: 看起来像这样:

let goodViews = scrollView.subviews.filter( {$0.frame.height > 7 && $0.frame.width > 7} )

Except I know that hard coding those values will get me in trouble someday, which is why I'd like the reference instead. 除非我知道对这些值进行硬编码有一天会给我带来麻烦,这就是为什么我想要参考。 Thanks! 谢谢!

Here is an option: 这是一个选项:

let bv = scrollView.showsVerticalScrollIndicator
let bh = scrollView.showsHorizontalScrollIndicator

scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false

let lowestView = scrollView.subviews.sorted(by: { $0.frame.maxY < $1.frame.maxY }).last?.frame.maxY ?? 0

scrollView.showsVerticalScrollIndicator = bv
scrollView.showsHorizontalScrollIndicator = bh

I only did a quick test, but seems reliable. 我只做了快速测试,但是看起来很可靠。

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

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