来自 UIScrollView 的非常奇怪的行为。请检查以下代码
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
scrView.delegate =self;
[scrView setContentSize:CGSizeMake(95000, self.view.bounds.size.height)];
scrView.backgroundColor = [UIColor clearColor];
Testview *test = [[Testview alloc]initWithFrame:CGRectMake(0, 0, scrView.contentSize.width, self.view.bounds.size.height)];
test.backgroundColor = [UIColor greenColor];
[scrView addSubview:test];
[scrView flashScrollIndicators];
[self.view addSubview:scrView];
self.view.backgroundColor = [UIColor clearColor];
}
Testview 是 Scrollview 的子视图。
@implementation Testview
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
}
在 Testview 类中,如果我调用方法 - (void)drawRect:(CGRect)rect,则 UIscrollview 变为空白并且无法在运行时查看滚动视图。但是如果我评论 drawRect 方法
@implementation Testview
//- (void)drawRect:(CGRect)rect {
//
// [super drawRect:rect];
//}
它工作得很好。我正在努力解决这个问题,请帮我解决这个问题。如果内容大小宽度和子视图宽度超过 95000,我需要 drawRect 工作。