2

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

我能做些什么?

4

1 回答 1

1
pageFrame.origin.x = (bounds.size.width * i) + PADDING;

将此部分更改为

pageFrame.origin.x = (bounds.size.width + PADDING) * i;
于 2012-06-01T08:29:24.673 回答