使用UIPageViewController设置页面卷曲动画

时间:2013-01-30 06:04:15

标签: ios objective-c uipageviewcontroller

我是iOS新手,我正在使用UIPageViewController。这是我的代码:

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController 
{
 firstVC *first1 = [[firstVC alloc] initWithNibName:@"firstVC" bundle:nil]; return first1; 
}


- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { 
secondVC *second1 = [[secondVC alloc] initWithNibName:@"secondVC" bundle:nil]; return second1;
} 




- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed { NSArray *viewControllers = nil; viewControllers = [NSArray arrayWithObjects:first,second, nil]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerSpineLocationMid animated:NO completion:NULL]; 
} 



-(UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation { 
NSArray *viewControllers = nil; viewControllers = [NSArray arrayWithObjects:second, first, nil]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerSpineLocationMid animated:YES completion:NULL]; return UIPageViewControllerSpineLocationMid; 
}




 - (void)viewDidLoad { [super viewDidLoad]; [self.navigationController setNavigationBarHidden:NO]; self.navigationController.navigationBar.tintColor = [UIColor blackColor]; self.title = @"DEMO"; NSDictionary *options = [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey: UIPageViewControllerOptionSpineLocationKey]; self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerSpineLocationMid options:options]; self.pageViewController.delegate = self; self.pageViewController.dataSource = self; first = [[firstVC alloc] initWithNibName:@"firstVC" bundle:nil]; second = [[secondVC alloc] initWithNibName:@"secondVC" bundle:nil]; NSArray *viewControllers = [NSArray arrayWithObjects:first,second,nil]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerSpineLocationMid animated:NO completion:nil]; [self addChildViewController:self.pageViewController]; [self.view addSubview:self.pageViewController.view]; self.modalPresentationStyle=UIModalPresentationCurrentContext; [self.pageViewController didMoveToParentViewController:self]; CGRect pageViewRect = self.view.bounds; pageViewRect = CGRectInset(pageViewRect, 20.0, 20.0); self.pageViewController.view.frame = pageViewRect; self.view.gestureRecognizers = self.pageViewController.gestureRecognizers; self.pageViewController.doubleSided=YES; } 

它在两个方向上加载双面页面,但是当我滑动页面并且仅显示一个视图时出现问题。我想要一个类似页面的动画。请帮忙。提前感谢您的帮助和支持。

1 个答案:

答案 0 :(得分:0)

你在哪里初始化你的UIPageViewController?

在初始化时你必须定义过渡样式,因为它是一个只读属性。

代码应如下所示;

   self.pageViewController = [[UIPageViewController alloc]
                             initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
                             navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal 
                             options:nil];