如何更改尺寸时,如何强制重绘(drawRect)SubView? [英] How Do I Force Redrawing (drawRect) of a SubView When it Changes Dimensions?

查看:119
本文介绍了如何更改尺寸时,如何强制重绘(drawRect)SubView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView,它包含一行 UIView 的子类。子类已重写 drawRect :并已设置 contentMode = UIViewContentModeRedraw

I have a UIView that contains a row of subclasses of UIView. The subclass has overridden drawRect: and has set contentMode = UIViewContentModeRedraw.

当用户压扁并拉伸父容器时,子视图挤压和拉伸。当形状发生变化时,我希望重复调用 drawRect 来更改子视图的内容。到目前为止,我一直没有成功。这样做的正确方法是什么?

As the user squashes and stretches the parent container the child views squash and stretch. As the shape change occurs I would like to have drawRect called repeatedly to change the contents of the child views. So far I have been unsuccessful. What is the correct way to do this?

干杯,

Doug

推荐答案

在Cocoa中,您很少(如果曾经)调用drawRect - 您只需将区域或视图标记为需要更新,它将被安排重新绘制。这允许将多个失效的重绘折叠在一起。

In Cocoa, you rarely (if ever) call drawRect - you just mark the region or view as needing update, and it will be scheduled for redrawing. This allows redraws for multiple invalidations to be collapsed together.

对于Cocoa Touch,您需要 [view setNeedsDisplay] setNeedsDisplayinRect:(CGRect)

For Cocoa Touch, you want either [view setNeedsDisplay], or setNeedsDisplayinRect:(CGRect)

这篇关于如何更改尺寸时,如何强制重绘(drawRect)SubView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆