0

スクロール ビューを作成し、2 つの xib 画面 (SVPage1.xib と SVPage2.xib) を追加して、両方の画面をめくることができるようにしようとしています。

scrollview と Page Control オブジェクトを作成しました。

これは私が.mファイルに持っているものです:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"SVPage1" owner:self options:nil];
    UIView *mainView = [subviewArray objectAtIndex:0];
    [self.scrollView addSubview:mainView];

    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * 2;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;

    NSArray *subviewArray2 = [[NSBundle mainBundle] loadNibNamed:@"SVPage2" owner:self options:nil];
    UIView *mainView2 = [subviewArray2 objectAtIndex:0];
    [self.scrollView addSubview:mainView2];

    //Set the content size of our scrollview according to the total width of our imageView objects.
    scrollView.contentSize = CGSizeMake(mainView.frame.size.width * 3, mainView2.frame.size.height);
}

#pragma mark - UIScrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
    // Update the page when more than 50% of the previous/next page is visible
    CGFloat pageWidth = self.scrollView.frame.size.width;
    int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    self.pageControl.currentPage = page;
}

2 番目の xib ファイルをロードすると、最初のファイルの上にロードされると思います。

プログラムを実行すると、画面に 2 番目の xib ファイルが表示され、他のページをめくると空白になります。2番目の.xibを追加しようとして、ひどく間違ったことをしていると思います...

何か案は?

4

1 に答える 1