はいあります。 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
それです!