[英]setNeedsDisplay doesn't work on subclass of UIImageView
import UIKit
class CustomView: UIView {
override func drawRect(rect: CGRect) {
print("Draw")
}
}
Drag a UIView, set its class to be CustomView
, create a reference customView
to it. 拖动一个UIView,将其类设置为CustomView
,为其创建一个引用customView
。
When I call customView.setNeedsDisplay()
, drawRect
of CustomView
get called. 当我打电话customView.setNeedsDisplay()
drawRect
的CustomView
被调用。
import UIKit
class CustomImageView: UIImageView {
override func drawRect(rect: CGRect) {
print("DrawImage")
}
}
Drag a UIImageView, set its class to be CustomImageView
, create a reference customImageView
to it. 拖动一个UIImageView,将其类设置为CustomImageView
,为其创建一个引用customImageView
。
When I call customImageView.setNeedsdisplay()
, nothing happen. 当我调用customImageView.setNeedsdisplay()
,什么都没有发生。 Why? 为什么?
The UIImageView class is optimized to draw its images to the display. UIImageView类经过优化,可以将其图像绘制到显示器上。 UIImageView does not call the drawRect: method of its subclasses. UIImageView不会调用其子类的drawRect:方法。 If your subclass needs to include custom drawing code, you should subclass the UIView class instead. 如果您的子类需要包含自定义绘图代码,则应改为UIView类的子类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.