当设备方向发生变化时,导致子视图重绘的正确方法是什么?
我有一个带有一个视图和一个子视图的视图控制器。当设备方向更改时,视图会自动重绘,但子视图不会。如果我明确执行 [subview setNeedsDisplay] 它会重绘,但我没有一个逻辑位置可以将该调用放入我的代码中。而且,由于我不必明确告诉视图重绘,所以告诉子视图重绘似乎是违反直觉的。有没有办法让子视图在视图重绘时自动重绘?
I have a view controller with a view and one subview. When the device orientation changes the view auto-redraws but the subview doesn't. If I explicitly do [subview setNeedsDisplay] it redraws but I don't have a logical place to put that call in my code. And, since I don't have to explicitly tell the view to redraw, it seems counter-intuitive to tell the subview to redraw. Is there a way to make the subview auto-redraw when the view redraws?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现以下方法有效。如果这不是最好的方法,请有人提供更好的方法。
在
subview.m
文件的initWithFrame:
方法中包含以下内容尽管这可以工作并且非常适合我的代码,但我不明白为什么子视图需要这些属性已设置,但视图未设置。
I found that the following works. If it isn't the best approach somebody please give a better way to do it.
Include the following in the
subview.m
file, in theinitWithFrame:
methodEven though this works and fits nicely into my code, I don't see why the subview needs these properties set but the view doesn't.
Swift 3/iOS10 语法:
Swift 3/iOS10 syntax: