自定义 UIView 的边界比框架更小

发布于 2024-10-28 00:52:34 字数 87 浏览 1 评论 0原文

是否可以创建一个边界小于框架的自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我的影子我的梦 2024-11-04 00:52:34

视图的边界表示视图自身坐标系中的边界矩形。框架是超级视图坐标系中的边界矩形。通过更改视图的变换,您可以轻松创建一个具有 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.

愁以何悠 2024-11-04 00:52:34

它绝对可以,这几乎就是滑动视图在幕后的工作原理。

It definitely can, it's pretty much how the Sliding Views work under the hood.

不即不离 2024-11-04 00:52:34

我认为框架和边界直接链接到视图的主层......但您可以添加一个子层并移动它。

I think frame and bounds is directly linked to the main layer of the view... but you could add a sublayer and move that.

廻憶裏菂餘溫 2024-11-04 00:52:34
  • 使该类成为 UIView 的子视图。
  • 将要显示的内容放在另一个视图中,并使用 -addSubview 附加它。
  • 确保子视图设置了 UIAutoresizingNone (或者设置了 self.autoresizesSubviews = NO),并且具有与其实际大小相对应的边界。
  • 设置 self.clipsToBounds = YES 。
  • 更新子视图框架的原点以调整子视图的哪一部分在前视图中可见,或增大主视图的边界以显示更多被剪裁的子视图。
  • Make the class a subview of UIView.
  • Put the content that you want to display in another view and attach it with -addSubview.
  • Make sure that the subview has UIAutoresizingNone set (or you set self.autoresizesSubviews = NO) and has bounds that correspond to its actual size.
  • Set self.clipsToBounds = YES.
  • Update the origin of the subview's frame to adjust which part of the subview is visible in the front view, or grow the bounds of the main view to show more of the clipped subview.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文