2

你好朋友,我希望我的页面像在 iBook 页面中一样卷曲,页面也应该根据手指移动而转动。请帮助提前谢谢..

4

1 回答 1

0

你需要实现 UIPageViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self addChildViewController:self.pageViewController];
    [self.view addSubview:self.pageViewController.view];
    [self.pageViewController didMoveToParentViewController:self];
    self.pageViewController.view.frame = self.view.bounds;
}

- (UIPageViewController *)pageViewController
{
    if (!_pageViewController) {
        _pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
                                                              navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                                                                            options:nil];
        _pageViewController.dataSource = self;
        _pageViewController.delegate = self;
        [_pageViewController setViewControllers:@[self.viewControllers.firstObject]
                                      direction:UIPageViewControllerNavigationDirectionForward
                                       animated:NO
                                     completion:nil];
    }
    return _pageViewController;
}

- (NSArray *)viewControllers // provide your view controller for each page
{
    if (!_viewControllers) {
        _viewControllers = @[
                             [UIViewController new],
                             [UIViewController new],
                             [UIViewController new],
                             [UIViewController new],
                             [UIViewController new],
                             ];
    }
    return _viewControllers;
}

#pragma mark - UIPageViewControllerDataSource

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    NSUInteger index = [self.viewControllers indexOfObject:viewController];
    if (index == 0) {
        return nil;
    }
    return [self.viewControllers objectAtIndex:--index];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    if ([self.viewControllers.lastObject isEqual:viewController]) {
        return nil;
    }
    NSUInteger index = [self.viewControllers indexOfObject:viewController];
    return [self.viewControllers objectAtIndex:++index];
}
于 2015-01-27T12:46:42.460 回答