- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 UIViewController
,在 willRotateToInterfaceOrientation
中,我正在调用 [self view] setNeedsLayout];
这个 View 调用了它的 subview (UIScrollView
)layoutSubviews
方法,但是 UIScrollView
没有调用 layoutSubviews
因为它的 subview 。这是应该的样子吗?我想如果你在一个 View 上调用 setNeedsLayout
,它会在每个 subview 和它们的 subview 上调用 layoutSubviews
以及...
我是否必须手动覆盖 UIScrollView
中的 layoutsubview
并为每个 subview 调用 setNeedsDisplay
?
谢谢。
最佳答案
我前段时间在我的应用程序中观察到同样的事情,似乎 setNeedsLayout
只影响 View 的 subview 而不会向下遍历。如果您使用自定义 View ,您可以轻松地将 View 子类化并在 setNeedsLayout
中迭代 subview ,并对它们执行显式 setNeedsLayout
。
如果您希望它成为默认行为,您可以覆盖类别中的方法,但我真的不会这样做,因为它会影响所有 View 并可能引入性能和其他意外问题。
你可以这样做
@interface UIView (Layout)
- (void)setNeedsLayoutRecursively;
@end
@implementation UIView (Layout)
- (void)setNeedsLayoutRecursively {
for (UIView *view in self.subviews) {
[view setNeedsLayoutRecursively];
}
[self setNeedsLayout];
}
@end
在浏览器中输入,未经测试
但是,请注意,这不是好的做法!您应该只更新需要更新的内容。这可能会导致严重的性能损失。谨慎使用!
关于objective-c - UIView subview 中的 setNeedsLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7695903/
我有一个带有单元格的 TableView ,有时它有一个可选的 UI 元素,有时它必须被删除。根据元素,标签会调整大小。 初始化单元格时,它比以后要窄。当我将数据设置到标签中时,从 cellForRo
我有一个分组格式的 UITableView,其中有几个单元格。单元格中有一个 UIView,我要向其添加另一个 UIView。当我更新第一个 UIView 的框架时,它不会改变它的位置和大小。 如果单
动画约束变化的标准方法是。 // Change constraints like: someConstraint.constant = 100 UIView.animate(withDuration:
我想知道 Apple 的 -setNeedsLayout 是如何工作的。 我已经知道它比直接调用 -layoutSubviews 更有效,因为我可能需要在一个方法中执行两次。 这正是我需要它的目的:一
UIView 方法 setNeedsLayout 和 setNeedsDisplay 之间的真正区别是什么? 像往常一样,文档对此模糊不清。 最佳答案 实际上文档对此很清楚: setNeedsLayo
一些 S.O.问题展示了一种自动布局技术,用于确定 View 满足其约束所需的最小尺寸:[header systemLayoutSizeFittingSize: UILayoutFittingComp
据我所知, -setNeedsLayout 方法仅将标志设置为 View ,以便在下一个更新周期布局 subview 。但是 layoutIfNeeded 立即调用 layoutSubviews 方法
从 OSX 10.7 开始,如果您希望执行 NSView 的手动布局,您应该通过覆盖 layout 方法来实现,并且无论何时您希望安排对该方法的调用,您只需执行以下操作: [myView setNee
在 iOS 上,是否有必要在以编程方式更改约束常量后进行任何 API 调用(例如 setNeedsLayout 或 layoutIfNeeded)?在我的用例中,我对动画变化不感兴趣。我相信存在一些错
我想在当前 ViewController 的底部显示一个 ViewController,具有特定的高度。然后我添加了将 ViewController 向上移动的功能,一直到 StatusBar 的后面
我的 ViewController 中有一个自定义 View ,我想更新它的一些信息。此信息是从 Firebase 异步绘制的。 我正在尝试使用 view.setNeedsDisplay 或 view
我有一个 UIViewController,在 willRotateToInterfaceOrientation 中,我正在调用 [self view] setNeedsLayout]; 这个 Vie
我已经阅读了一些关于 setNeedsLayout 和 layoutIfNeeded 之间的区别的文章,而我关注的是: 1。如果我想要立即布局,我是否需要同时调用这两个方法,因为我已经多次看到这种组合
我的图层有几个动态属性,这些属性会影响图层本身的布局和/或显示。如果我从属性的 setter 发送 setNeedsLayout/setNeedsDisplay 可以吗?还是由 setter 的调用者
似乎呈现和关闭 View Controller 都会提示 呈现 View 以布局其 subview 和/或更新其约束。对于繁重的 View 层次结构,这会引入性能问题。再次 - 这是现有的,当前显示的
我是否将这些东西放入显示方法中?或者有类似的东西吗? 最佳答案 从 OSX 10.7 开始: - (void)layout 相当于layoutSubviews 现在有一个相同的setNeedsLayo
我已成功对 UITableViewCell 进行子类化,并且我正在使用子类在我的应用程序中布局一些 TableViewCell。现在,我正在尝试将图像延迟加载到单元格中。根据日志,图像下载工作正常,但
我正在调用 API。根据我返回的 json 数据,我正在 viewDidLoad() 中修改我的 View Controller ,以便更改我的 View 设计以尽可能最好地显示给定数据。 我所做的是
我知道自动布局链基本上包含 3 个不同的过程。 更新约束 布局 View (这里是我们计算帧的地方) 显示 我不太清楚-setNeedsLayout 和-setNeedsUpdateConstrain
我有一个主视图 Controller 显示在屏幕上,一个类(代表)在后台运行获取位置。当我得到结果时,我调用 View Controller 中的委托(delegate)方法来更新屏幕上的标签。我尝试
我是一名优秀的程序员,十分优秀!