Apple の WWDC 2010 チュートリアル ビデオ「Designing Apps with Scroll Views」は、iOS 4 ではうまく機能しますが、iOS 5 ではページが中央に配置されません。
のようだ
pagingScrollViewFrame.origin.x -= PADDING;
iOS 5 では動作しません。
私のコードは次のとおりです。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
#define PADDING 10
- (void)loadView
{
// Step 1: make the outer paging scroll view
CGRect pagingScrollViewFrame = [[UIScreen mainScreen] bounds];
pagingScrollViewFrame.origin.x -= PADDING;
pagingScrollViewFrame.size.width += (2 * PADDING);
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor whiteColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(pagingScrollView.bounds.size.width * 6, pagingScrollView.bounds.size.height);
pagingScrollView.delegate = self;
self.view = pagingScrollView;
for(int i = 0; i < 6; i++)
{
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor blueColor];
CGRect bounds = pagingScrollView.bounds;
CGRect pageFrame = bounds;
pageFrame.size.width -= (2 * PADDING);
pageFrame.origin.x = (bounds.size.width * i) + PADDING;
view.frame = pageFrame;
[pagingScrollView addSubview:view];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
私に何ができる?