UIScrollView が正しく機能するように、UIView に UIScrollView を追加する方法について質問があります。
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, container.frame.size.width/2, container.frame.size.height/2)];
scroll.pagingEnabled = YES;
scroll.scrollEnabled = YES;
[scroll setBackgroundColor:[UIColor redColor]];
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++)
{
CGFloat xOrigin = i * container.frame.size.width/2;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(xOrigin, 0, container.frame.size.width, container.frame.size.height)];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:awesomeView];
[awesomeView release];
}
scroll.contentSize = CGSizeMake(container.frame.size.width/2 * numberOfViews, container.frame.size.height);
[container addSubview:scroll];
上記のコードはチュートリアルからのものです: http://idevzilla.com/2010/09/16/uiscrollview-a-really-simple-tutorial/ しかし、それは私にとってはうまくいきません。
編集:
スクロールビューを適切に設定しても機能しないという問題がある場合は、スクロールビューに別の UIView を重ねていないことを確認してください。それが私の問題でした。 解決しました!