![](/img/trans.png)
[英]Custom UIView's drawRect never called if initial frame is CGRectZero
[英]Custom UIView in UIScrollView drawRect never called
我有一個控制器:
- (void)viewDidLoad {
[super viewDidLoad];
// Add a scroolView
self.scroolViewDay.scrollEnabled = YES;
// Compute the content Size of the TableDays
self.scroolViewDay.contentSize = CGSizeMake(self.scroolViewDay.frame.size.width,
80 * 48); // TO MODIFY!
[self.scroolViewDay addSubview:self.tableDays];
[self.tableDays setNeedsDisplay];
}
該控制器具有XIB
其中UIScrollView
是成。 自定義視圖TableDays有一個永遠不會被調用的自定義drawRect
:
- (void)drawRect:(CGRect)rect {
NSLog(@"sono in drawRect");
}
為什么?
-(void) setNeedsDisplay {
[self.subviews makeObjectsPerformSelector:@selector(setNeedsDisplay)];
[super setNeedsDisplay];
}
添加此代碼,並在主視圖中覆蓋setNeedsDisplay方法,我希望您知道應重新繪制所有子視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.