简体   繁体   English

如何调用 -(void)drawRect:(CGRect)rect

[英]How to call -(void)drawRect:(CGRect)rect

How Can i Call怎么打电话

-(void)drawRect:(CGRect)rect

in https://github.com/stkim1/MTImageMapView/blob/master/MTImageMapView/MTImageMapView.mhttps://github.com/stkim1/MTImageMapView/blob/master/MTImageMapView/MTImageMapView.m

From Another UiViewController Periodically With NSTimer从另一个UiViewController定期使用NSTimer

From the documentation :文档

Discussion讨论

The default implementation of this method does nothing.此方法的默认实现不执行任何操作。 Subclasses that use technologies such as Core Graphics and UIKit to draw their view's content should override this method and implement their drawing code there.使用 Core Graphics 和 UIKit 等技术绘制其视图内容的子类应覆盖此方法并在那里实现其绘制代码。 You do not need to override this method if your view sets its content in other ways.如果您的视图以其他方式设置其内容,则不需要覆盖此方法。 For example, you do not need to override this method if your view just displays a background color or if your view sets its content directly using the underlying layer object.例如,如果您的视图仅显示背景颜色或者您的视图直接使用底层图层对象设置其内容,则不需要覆盖此方法。

... ...

If you subclass UIView directly, your implementation of this method does not need to call super.如果你直接UIView ,你的这个方法的实现不需要调用 super。 However, if you are subclassing a different view class, you should call super at some point in your implementation.但是,如果您要对不同的视图类进行子类化,则应在实现中的某个时刻调用 super。

This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view.当第一次显示视图或发生使视图的可见部分无效的事件时,将调用此方法。 You should never call this method directly yourself .你永远不应该自己直接调用这个方法 To invalidate part of your view, and thus cause that portion to be redrawn, call the setNeedsDisplay or setNeedsDisplayInRect: method instead.要使视图的一部分无效,从而导致该部分被重绘,请改为调用setNeedsDisplaysetNeedsDisplayInRect:方法。

是的,我找到了解决方案,我在drawrect函数的末尾调用了一个带有计时器的函数,并在其中调用了setNeedsDisplay()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM