获取 UIView 的可见矩形
我有一个包含自定义 UIView 的 UIScrollView。在自定义 UIView
内部,我想知道它可见的矩形(即未剪切)。
快速的解决方案是让自定义 UIView 假设父级是 UIScrollView 并通过它获取内容大小,但我正在寻找一个不涉及 make 的更好的解决方案这样的假设。
I have a UIScrollView
that contains a custom UIView
. Inside the custom UIView
, I'd like to know the rectangle in which it's visible (i.e. not clipped).
The quick-n-dirty solution is to have the custom UIView assume that the parent is a UIScrollView
and get the content size through it, but I'm looking for a better solution that doesn't involve make such assumptions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该可以解决问题,
在 UIView 中使用它,它应该为您提供代表该视图在其超级视图(UIScrollView)中的可见部分的矩形(如果有)。我在这里假设层次结构中它们之间没有视图,但如果有的话,修改代码应该是微不足道的。
希望我能帮忙!
This should do the trick
Use that in the UIView and it should get you the rectangle (if any) that represents the visible section of that view in it's superview (The UIScrollView). I'm assuming here that there is no view between them in the hierarchy, but if there is, fiddling the code should be trivial.
Hope I could help!
如果您能提供更多关于您想要实现的目标的信息,将会有所帮助。
如果你想知道超级视图的大小,你可以这样做:
It would help if you would give more info on what is that you are trying to accomplish.
If you want to know the size of the super view you can do this:
雨燕3
Swift 3