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 が機能する必要があります。