日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

关于Page翻页效果--Page View Controller

發(fā)布時間:2023/11/27 生活经验 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于Page翻页效果--Page View Controller 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Page View Controllers
你使用一個page view controller用page by page的方式來展示內(nèi)容。一個page view controller管理一個self-contained視圖架構(gòu)。這個架構(gòu)的父視圖由page View controller管理,并且子視圖由你提供的view Controllers管理。

一,解析Page View Controller
一個page view controller有一個單獨的視圖,是你的內(nèi)容的存放的地方。
下圖顯示了page view interface的結(jié)構(gòu):最外面的棕色視圖是父視圖控制器,不是page view controller自身。page view controller沒有自己的UI;然而,它對它的children做一個翻頁效果。

?

二,page view controller interface的對象:
一個可選的代理,一個可選的數(shù)據(jù)源,一組current view controllers,一組手勢識別者

?

數(shù)據(jù)源按需提供viewControllers。
委托提供響應(yīng)基于手勢的導(dǎo)航和方向更改。
view Controllers的數(shù)組包含當(dāng)前要顯示的content view controller。數(shù)組中的items的數(shù)量基于傳遞給page view controller的選項。
手勢識別者只有在數(shù)據(jù)源被指定時才存在。這些手勢識別者使用戶通過輕擊、flicking(快速滑動)或拖動翻頁。

三,創(chuàng)建page view controller interface:
page view controller的view可以被縮放和嵌入到一個視圖層次架構(gòu)中。這意味著,不像一個導(dǎo)航控制器或tab bar controller,page view controller可以在廣闊的范圍內(nèi)使用,而不是一些特別的情況。

1,通過stroyboard創(chuàng)建page view controller: Page-Based Application Xcode模版創(chuàng)建一個新的帶page view controller的工程。
要添加一個page view controller到一個已經(jīng)存在的storyboard:
1)拖動一個page view controller,并添加一個page view controller scene 到你的storyboard.
2)在屬性檢查器中,設(shè)置適當(dāng)?shù)倪x項。
3)可選地,設(shè)置一個委托,數(shù)據(jù)源
4)。。。

2,通過代碼創(chuàng)建一個page view controller:
1)通過initWithTransitionStyle:navigationOrientation:options:方法創(chuàng)建一個page view controller
2)可選地,設(shè)置一個代理、數(shù)據(jù)源
3)設(shè)置初始的content view controllers
4) 在屏幕上顯示page view controller的view。

3,設(shè)置最初的view controller:無論你是通過代碼創(chuàng)建還是通過IB創(chuàng)建了一個page view controller,你都需要在將其顯示到屏幕之前指定一個初始的view controller。
調(diào)用setViewControllers:direction:animated:completion:方法。

如果page view controller沒有initial view controller,它的shouldAutorotateToInterfaceOrientation:返回NO,并拋出一個異常。

四,自定義初始化行為:
在初始化時,你傳遞給initWithTransitionStyle:navigationOrientation:options:方法的參數(shù)值和選項來自定義一個page view controller。在初始化后,這些屬性都是只讀的。你可以自定義:
1)The direction in which navigation occurs.
2)The location of the spine.(書脊的位置)
3)The transition style. In iOS 5, the only valid transition style is UIPageViewControllerTransitionStylePageCurl.

例如,

Listing 3-1? Customizing a page view controller
NSDictionary * options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:UIPageViewControllerSpineLocationMid] forKey:UIPageViewControllerOptionSpineLocationKey];

UIPageViewController *pageViewController = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options];

五、在運(yùn)行時使用代理自定義行為:
UIPageViewControllerDelegate協(xié)議:可以在設(shè)備方向更改時和用戶導(dǎo)航到一個新頁時執(zhí)行動作,并且它可以更新書脊的位置來響應(yīng)方向的轉(zhuǎn)變。

六、通過數(shù)據(jù)源提供內(nèi)容:
數(shù)據(jù)源的方法被當(dāng)前顯示的view controller調(diào)用,并返回它之前和之后的view controller。為了簡化查找前面和后面的viewcontroller,你可以在你的view controller里存儲額外的信息,例如一個page number。
如果指定了數(shù)據(jù)源,page view controller將關(guān)聯(lián)手勢識別到它的view。這些手勢通過gestureRecognizers屬性訪問。

要移動手勢識別到另一個view,傳遞gestureRecognizers屬性的值給目標(biāo)view的addGestureRecognizer:方法。

例如,如果你的page view controller沒有充滿屏幕,你將手勢識別傳遞給其superview,可以更好地翻頁,而不用必須在page view controller內(nèi)翻頁。

七,通過設(shè)置current view controller提供內(nèi)容:
setViewControllers:direction:animated:completion:方法直接控制顯示哪些內(nèi)容。
如果你沒有設(shè)置數(shù)據(jù)源,你需要提供UI來移動pages,例如前進(jìn)和后退按鈕。手勢驅(qū)動的導(dǎo)航只有在在你提供了數(shù)據(jù)源的時候才可用。

八,特別考慮Right-to-Left和Bottom-to-Top Content:
要通過數(shù)據(jù)源,使用一個page view controller來顯示一個right-to-left或bottom-to-top內(nèi)容,只需要反轉(zhuǎn)下面兩個方法的實現(xiàn):
1)在你的數(shù)據(jù)源中,實現(xiàn)pageViewController:viewControllerBeforeViewController: 并返回之后的的viewController
2)pageViewController:viewControllerAfterViewController:返回前面的viewController>

并且,你一般要設(shè)置書脊的位置為UIPageViewControllerSpineLocationMax

轉(zhuǎn)載于:https://www.cnblogs.com/zhwl/archive/2013/01/05/2846331.html

總結(jié)

以上是生活随笔為你收集整理的关于Page翻页效果--Page View Controller的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。