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
我能做些什么?