3

我是IOS新手,所以请帮我指导这个问题。

我正在处理三个视图,它们打开由scroll view和连接的三个不同图像pagination。我正在使用XIB来获取分页逻辑和滚动视图。

我面临两个问题:

  1. 我无法让页面指示器以不同的视图出现在屏幕上

  2. 一旦到达第三个视图,我发现很难移动到下一个视图控制器。

我正在关注 Ray Wanderlich 的本教程。一旦用户尝试在到达最后一页时滑动到下一页,我对在哪里添加代码以移动到下一个视图控制器感到震惊。

我的代码是这样的:

- (void)viewDidLoad {
[super viewDidLoad];


   self.navigationController.navigationBarHidden =YES;
// Set up the image we want to scroll & zoom and add it to the scroll view
self.pageImages = [NSArray arrayWithObjects:
                   [UIImage imageNamed:@"IMAGE1.png"],
                   [UIImage imageNamed:@"IMAGE2.png"],
                   [UIImage imageNamed:@"IMAGE3.png"],
                  // [UIImage imageNamed:@"photo4.png"],
                  // [UIImage imageNamed:@"photo5.png"],
                   nil];

NSInteger pageCount = self.pageImages.count;

// Set up the page control
self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = pageCount;

// Set up the array to hold the views for each page
self.pageViews = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < pageCount; ++i) {
    [self.pageViews addObject:[NSNull null]];
}

}

- (void)loadVisiblePages {
// First, determine which page is currently visible
CGFloat pageWidth = self.scrollView.frame.size.width;
NSInteger page = (NSInteger)floor((self.scrollView.contentOffset.x * 2.0f + pageWidth) / (pageWidth * 2.0f));

// Update the page control
self.pageControl.currentPage = page;

NSLog(@"One %d",page);

if (page == 2) {

    page = 3;

    if(page == 3){
         NSLog(@"Working");

        SignInViewController *view = [[SignInViewController alloc]initWithNibName:@"SignInViewController" bundle:nil];
        [self.navigationController pushViewController:view animated:NO];
        [view release];
        view=nil;
    }

}

// Work out which pages we want to load
NSInteger firstPage = page - 1;
NSInteger lastPage = page + 1;

// Purge anything before the first page
for (NSInteger i=0; i<firstPage; i++) {
    [self purgePage:i];
}


    // Load pages in our range
for (NSInteger i=firstPage; i<=lastPage; i++) {
    [self loadPage:i];


}


    // Purge anything after the last page
for (NSInteger i=lastPage+1; i<self.pageImages.count; i++) {
    [self purgePage:i];

}

}

我试图将我的视图控制器的行添加为:

SignInViewController *view = [[SignInViewController alloc]initWithNibName:@"SignInViewController" bundle:nil];
            [self.navigationController pushViewController:view animated:NO];
            [view release];
            view=nil; 

但这会使第三张图像消失,并在SignInView用户尝试从第二张图像滑动到第三张图像时直接将用户带到我的控制器页面。

我应该怎么做才能让用户看到第三张图像,然后检测到滑动并移动到下一个带有动画的视图控制器。我尝试使用滑动动画和检测,但它对我不起作用。我需要在哪里编码以及如何提供帮助!

4

1 回答 1

1

I think it might be late to reply but may be you still might be struck and need help then here is the solution to your second issue:

Answer to part 2.->

try and add this code

if (page == 2) {

    page = 3;

    if(page == 3){

        NSLog(@"content ofset--  %f",self.scrollView.contentOffset.x);

        if (self.scrollView.contentOffset.x>=700)
        {
            SignIn2ViewController *view = [[SignIn2ViewController alloc]initWithNibName:@"SignIn2ViewController" bundle:nil];
            [self.navigationController pushViewController:view animated:NO];
            [view release];
            view=nil;
        }

    }
}

You can check for the offset's value to according to your need. may be this works for u.

and answer to part 1. -->try to read Ray Wanderlich tutorial again and check the settings of XIB you might have skipped some information to be added on outlets or page indicators.

Hope it works for you.

于 2013-04-26T07:28:21.560 回答