2013年3月28日 星期四

UIPageViewController

簡單翻譯解釋一下 沒翻譯就是我還沒用到

先看UIPageViewController 的 init 方法
- (id)initWithTransitionStyle:(UIPageViewControllerTransitionStyle)style navigationOrientation:(UIPageViewControllerNavigationOrientation)navigationOrientation options:(NSDictionary *)options;

要給的三個參數分別為
UIPageViewControllerTransitionStyle(換頁方式)
typedef NS_ENUM(NSInteger, UIPageViewControllerTransitionStyle) {
    UIPageViewControllerTransitionStylePageCurl = 0,  //向書本一樣的翻頁樣式
    UIPageViewControllerTransitionStyleScroll = 1     //ScrollView平滑捲動樣式
};

UIPageViewControllerNavigationOrientation(捲動方向)
typedef NS_ENUM(NSInteger, UIPageViewControllerNavigationOrientation) {
    UIPageViewControllerNavigationOrientationHorizontal = 0, //水平捲動
    UIPageViewControllerNavigationOrientationVertical = 1    //垂直捲動
};

options(書脊設定)
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey: UIPageViewControllerOptionSpineLocationKey];

typedef NS_ENUM(NSInteger, UIPageViewControllerSpineLocation) {
    UIPageViewControllerSpineLocationNone = 0, 
    UIPageViewControllerSpineLocationMin = 1,  //書脊在最左邊, 同時間畫面顯示一個viewController
    UIPageViewControllerSpineLocationMid = 2,  //書脊在最中間, 同時間畫面顯示兩個viewController
    UIPageViewControllerSpineLocationMax = 3   //書脊在最右間, 同時間畫面顯示一個viewController
};

UIPageViewController有一個屬性
@property (nonatomic, getter=isDoubleSided) BOOL doubleSided; // Default is 'NO'.
只會在換頁方式為PageCurl有作用, 一頁書頁是單面還是雙面的, Apple Document有介紹, 有空我在詳看

另外有兩個方法
- (void)willMoveToParentViewController:(UIViewController *)parent NS_AVAILABLE_IOS(5_0);
- (void)didMoveToParentViewController:(UIViewController *)parent NS_AVAILABLE_IOS(5_0);
想像成 viewWillxxx 跟 viewDidxxx, 是要寫在PageContent內容頁的, 告知內容頁說 將要xxx 跟 已經xxx

這中文不太好解釋 看這邊有不錯的英文說明


然後讓UIPageViewController顯示
- (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;
viewControllers傳入的是array of viewControllers
如果書脊中間 則要傳入的array內容為兩個viewController, 否則就一個


UIPageViewController 有兩個 protocol
@protocol UIPageViewControllerDataSource <NSObject>
@required
//當手指滑往上一頁, return欲顯示出上一頁的UIViewController
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController;
//當手指滑往下一頁, return欲顯示出下一頁的UIViewController
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController;

@optional
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0); //告知PageViewController一共有幾個Page, 用於顯示PageControl
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0); //起始頁面的Index

@protocol UIPageViewControllerDelegate <NSObject>
@optional
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers NS_AVAILABLE_IOS(6_0);
//換頁完成呼叫, 會告知動畫目前UIPageViewController, 翻頁動畫是否有跑, 上一頁的UIViewController, 是否有翻頁
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed;
- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation;

沒有留言:

張貼留言