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この目的に役立つ でビューをバックアップしてみてください。

于 2013-10-17T10:43:33.953 に答える
0

私の質問に答えます。CATiledLayer レイヤーを使用すると、scrollview に指定された最大幅のサブビューに関係なく、UIVIew の -drawRect: を使用できます。ただし、-drawRect: メソッドは、タイルを表示する必要があるたびに呼び出されます。このコードは私を助けました。

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