UIView 布局子视图委托

发布于 2024-09-04 17:43:54 字数 169 浏览 2 评论 0原文

我发现自己需要支持为 UIView 委派 layoutSubviews 的责任。这是为了避免必须创建一个特定的子类来实现layoutSubviews方法。我怀疑我发现自己想要这种替代方案的原因可能是因为我错过了一些基本的 UIKit 设计注意事项,或者?或者我应该继续创建自己的 UIView 子类来支持这种类型的布局委托?

I find myself wanting support for delegating the responsibility of layoutSubviews for a UIView. This to avoid having to make a specific subclass just to implement the layoutSubviews method. I'm suspecting the reason I found my self wanting this alternative might be because I've missed some fundamental UIKit design considerations, or? Or should I just go ahead and make my own UIView subclass with support for this type of layout delegation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

著墨染雨君画夕 2024-09-11 17:43:54

每当您需要自定义布局时,您都会想要创建一个子类,但无法委托。这也是唯一明智的方法 - 如果您在超级视图中包含一组视图,则该视图应该控制其子视图布局以实现可维护性。

您也不必在layoutSubviews中进行视图布局 - 如果您不需要可重用的东西,您可以在创建超级视图时简单地创建布局,并在此时分配位置和大小。

You're going to want to create a subclass whenever you need a custom layout, there is no way to delegate. It's also the only sane way to do it- if you're containing a set of views in a superview, that view should control its subview layout for maintainability.

You also don't have to do view layout in layoutSubviews- you can simply create the layout when you create the superview, and assign positions and sizes at that point, if you don't need something reusable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文