是的。您將使用UIPageViewController
。 UIPageViewController
具有根據用戶是向左或向右滑動而被調用的數據源和委託方法。它基本上說「嘿,給我UIViewController,我應該顯示之前或之後這個UIViewController」。
這裏有一個例子:
MyPageViewController.h:
@interface MyPageViewController : UIPageViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate>
@end
MyPageViewController.m:
#import "MyPageViewController.h"
@implementation MyPageViewController
- (id)init
{
self = [self initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
if (self) {
self.dataSource = self;
self.delegate = self;
self.title = @"Some title";
// set the initial view controller
[self setViewControllers:@[[[SomeViewController alloc] init]]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:NULL];
}
return self;
}
#pragma mark - UIPageViewController DataSource methods
- (UIViewController *)pageViewController:(UIPageViewController *)pvc
viewControllerBeforeViewController:(UIViewController *)vc
{
// here you put some logic to determine which view controller to return.
// You either init the view controller here or return one that you are holding on to
// in a variable or array or something.
// When you are "at the end", return nil
return nil;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pvc
viewControllerAfterViewController:(UIViewController *)vc
{
// here you put some logic to determine which view controller to return.
// You either init the view controller here or return one that you are holding on to
// in a variable or array or something.
// When you are "at the end", return nil
return nil;
}
@end
這就是它!