0

来自 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 工作。

4

2 回答 2

1

你的视野对普通人来说太大了-drawRect:CATiledLayer您应该尝试使用用于此目的的 a 来支持您的观点。

于 2013-10-17T10:43:33.953 回答
0

回答我的问题。如果我们使用 CATiledLayer 层,您将能够使用 UIVIew 的 -drawRect: ,而不管为滚动视图提供的最大宽度子视图。但是每次需要显示图块时都会调用 -drawRect: 方法。这段代码帮助了我。

+ (Class) layerClass
{
    return [CATiledLayer class];
}
于 2013-10-18T06:08:38.350 回答