自定义 UIView 的边界比框架更小
是否可以创建一个边界小于框架的自定义 uiview(从笔尖加载)。所以我想展示框架/视图的一部分。按下按钮时,我想将边界滑动到右侧以查看整个框架。这可以做到吗?
Is it possible to create a custom uiview (loaded from a nib) with bounds smaller than the frame. So I would like to show a part of the frame/view. On a button press I want to slide the bounds to the right to see the whole frame. Can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
视图的边界表示视图自身坐标系中的边界矩形。框架是超级视图坐标系中的边界矩形。通过更改视图的变换,您可以轻松创建一个具有 origin={0, 0} 和 size={1, 1} 的边界矩形,即使视图的框架是 origin={0, 0}, size={320, 480 }。该视图可能会覆盖整个屏幕,但边界大小仍然只有 1 × 1 单位。
我明白你想要做什么,这与bounds!=框架确实是不同的事情。您正在谈论拥有一个通过封闭视图仅部分可见的内容视图。这正是 UIScrollView 为您所做的。
A view's bounds represents the bounding rectangle in the view's own coordinate system. The frame is the bounding rectangle in the superview's coordinate system. By changing a view's transform, you could easily create a bounds rectangle with origin={0, 0} and size={1, 1}, even though the view's frame was origin={0, 0}, size={320, 480}. That view might cover the entire screen, but the bounds is still only 1 unit by 1 unit in size.
I see what you're trying to do, and that's really a different thing from bounds != frame. You're talking about having a content view that's only partially visible through an enclosing view. This is exactly what UIScrollView does for you.
它绝对可以,这几乎就是滑动视图在幕后的工作原理。
It definitely can, it's pretty much how the Sliding Views work under the hood.
我认为框架和边界直接链接到视图的主层......但您可以添加一个子层并移动它。
I think frame and bounds is directly linked to the main layer of the view... but you could add a sublayer and move that.
-addSubview
附加它。UIAutoresizingNone
(或者设置了self.autoresizesSubviews = NO
),并且具有与其实际大小相对应的边界。-addSubview
.UIAutoresizingNone
set (or you setself.autoresizesSubviews = NO
) and has bounds that correspond to its actual size.self.clipsToBounds = YES
.