如何在iOS上用手指移动像iBook一样卷曲页面?

时间:2013-06-06 06:26:24

标签: animation ibooks page-curl

你好朋友,我希望我的页面像他们在iBook页面中那样卷曲,页面也应该根据fingure运动转动。请帮忙 提前谢谢..

1 个答案:

答案 0 :(得分: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];
}