单击“跳过”按钮时,UIPageViewController移至下一张图像

时间:2019-03-25 12:33:29

标签: objective-c iphone xcode8 uipageviewcontroller uipagecontrol

UIPageViewController的imageview中显示了6张图像。我设法显示这些图像,但也想在图像上添加一个SKIP按钮。单击“跳过”时,应移至下一张图像。但是没办法

HelpScreen.m

- (void)viewDidLoad {
    [super viewDidLoad];
    self.pageImgs = @[@"1.png", @"2.png", @"3.png", @"4.png",@"5.png",@"6.png"];

    self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

    self.pageController.dataSource = self;
    [[self.pageController view] setFrame:CGRectMake(0, 0, [[self view] bounds].size.width, [[self view] bounds].size.height + 37)];

    HelpChildScreen *initialViewController = [self viewControllerAtIndex:0];

    NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];

    [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

    [[UIPageControl appearance] setPageIndicatorTintColor:[UIColor grayColor]];
    [[UIPageControl appearance] setCurrentPageIndicatorTintColor:[UIColor whiteColor]];
    [[UIPageControl appearance] setBackgroundColor: [[UIColor blackColor] colorWithAlphaComponent:0.1f]];
    [[UIPageControl appearance] setOpaque:YES];

    [self addChildViewController:self.pageController];
    [[self view] addSubview:[self.pageController view]];
    [self.pageController didMoveToParentViewController:self];
}
- (HelpChildScreen *)viewControllerAtIndex:(NSUInteger)index {

    HelpChildScreen *childViewController = [[HelpChildScreen alloc] initWithNibName:@"HelpChildScreen" bundle:nil];
    childViewController.index = index;
    childViewController.imgName = self.pageImgs[index];

    return childViewController;

}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {

    NSUInteger index = [(HelpChildScreen *)viewController index];

    if (index == 0) {
        return nil;
    }

    index--;

    return [self viewControllerAtIndex:index];

}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
    // The number of items reflected in the page indicator.
    return 6;
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
    // The selected item reflected in the page indicator.
    return 0;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {

    NSUInteger index = [(HelpChildScreen *)viewController index];
    HelpChildScreen *childViewController = [HelpChildScreen alloc];

    index++;

    if (index == 6) {
        return nil;
    }

    return [self viewControllerAtIndex:index];

}

HelpChildScreen.m

- (void)viewDidLoad {
    [super viewDidLoad];
    if(self.index==5)
        [_btnSkip setTitle:@"Done" forState:UIControlStateNormal];

   self.pageImgs = @[@"1.png", @"2.png", @"3.png", @"4.png",@"5.png",@"6.png"];

    self.screenNumber.text = [NSString stringWithFormat:@"Screen #%ld", (long)self.index];

    self.img.image = [UIImage imageNamed:_imgName];
}

如何添加按钮动作,单击后触发移动到下一张图像? 任何想法/建议都会有所帮助

0 个答案:

没有答案