gpt4 book ai didi

ios - 为什么 drawRect : work without calling [super drawrect:rect]?

转载 作者:技术小花猫 更新时间:2023-10-29 10:58:07 27 4
gpt4 key购买 nike

我正在覆盖 drawRect: 在我的一个 View 中,它甚至在不调用 [super drawrect:rect] 的情况下也能工作。这是如何运作的?

- (void)drawRect:(CGRect)rect{  
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(context, kCGBlendModeDestinationOver);
[[UIColor clearColor] setFill];
UIRectFill(CGRectMake(0,0,100,100));
}

最佳答案

来自文档:

"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"

也来自文档..

"If you subclass UIView directly, your implementation of this method does not need to call super. However, if you are subclassing a different view class, you should call super at some point in your implementation."

Link to the documentation

我假设您的父类(super class)是 UIView。因此即使 [super drawrect:rect] 没有被调用它也能工作。因为 drawRect: 因为 UIView 什么都不做。所以在这种情况下你是否调用 [super drawrect:rect] 没有区别。

关于ios - 为什么 drawRect : work without calling [super drawrect:rect]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26479524/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com