请教一个关于UIPageViewController的内存linux 消耗内存脚本问题

UIPageViewController手势识别-ios,uigesturerecognizer-CodeGo.net
UIPageViewController手势识别
我已经工作了一段时间的应用程序,但我也不会问这个问题,由于保密协议。
我有一个UIPageViewController负载与我的ViewController。视图控制器有哪些是由PageViewControllers手势识别器被重写按钮。比如我有右侧的的ViewController的一个按钮,当按下按钮时,PageViewController接管并翻动书页。
我怎样才能使按钮接收触摸并取消在PageViewController的手势识别?
我觉得PageViewController让我的ViewController的视图的子视图。
我知道我可以关掉所有的手势,但这不是我想要的效果。
我宁愿不子类化PageViewController苹果表示这个类是被继承。
本文地址 :CodeGo.net/367807/
-------------------------------------------------------------------------------------------------------------------------
1. 您可以覆盖-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch为更好的控制,当PageViewController应该得到触摸,而不是。看看在开发的API手势识别“,从分析润色防止手势识别”
我的解决方案看起来像这样在RootViewController的为UIPageViewController:
在viewDidLoad中:
//EDITED Need to take care of all gestureRecogizers. Got a bug when only setting the delegate for Tap
for (UIGestureRecognizer *gR in self.view.gestureRecognizers) {
gR.delegate =
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
//Touch gestures below top bar should not make the page turn.
//EDITED Check for only Tap here instead.
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
CGPoint touchPoint = [touch locationInView:self.view];
if (touchPoint.y & 40) {
return NO;
else if (touchPoint.x & 50 && touchPoint.x & 430) {//Let the buttons in the middle of the top bar receive the touch
return NO;
return YES;
而且不要忘记设置RootViewController的为UIGestureRecognizerDelegate。
(仅供参考,我只在横向模式。)
这里是另一种解决方案,它可以在被添加viewDidLoad模板后的权利self.view.gestureRecognizers = self.pageViewController.gestureRecognizers部分从Xcode的模板。它与手势识别或处理其代表的胆量。它只是移除的views水tap手势识别,只留下swipe识别。
self.view.gestureRecognizers = self.pageViewController.gestureR
// Find the tap gesture recognizer so we can remove it!
UIGestureRecognizer* tapRecognizer =
for (UIGestureRecognizer* recognizer in self.pageViewController.gestureRecognizers) {
if ( [recognizer isKindOfClass:[UITapGestureRecognizer class]] ) {
tapRecognizer =
if ( tapRecognizer ) {
[self.view removeGestureRecognizer:tapRecognizer];
[self.pageViewController.view removeGestureRecognizer:tapRecognizer];
我们可以在页面之间切换 CodeGo.net,你必须swipe。水tap现在只能在页面视图顶部的工作,你的控件(这是我在后)。
我有这个问题。样品和做这的loadView或viewDidLoad中:
self.view.gestureRecognizers=self.pageViewController.gestureR
这将替换从视图控制器视图与他们的UIPageViewController的手势识别。现在,当触摸发生时,他们首先通过页面视图控制器手势识别发送-如果它们不匹配,它们被发送到子视图。
只是那行,一切工作正常。
设置gestureRecognizers委派到的ViewController如下的iOS6的不再起作用
for (UIGestureRecognizer *gR in self.view.gestureRecognizers) {
gR.delegate =
在iOS6的,你pageViewController的gestureRecognizers委托设置为的ViewController崩溃
如果你',你已经子类化一个按钮,你可以重写的touchesBegan,touchesMoved和touchesEnded,调用自己的纲领性页转到适当的,但不能调用super并通过触动了通知链。
另外这个(感谢帮助,有说关于代表):
// add UIGestureRecognizerDelegate
NSPredicate *tp = [NSPredicate predicateWithFormat:@"self isKindOfClass: %@", [UITapGestureRecognizer class]];
UITapGestureRecognizer *tgr = (UITapGestureRecognizer *)[self.pageViewController.view.gestureRecognizers filteredArrayUsingPredicate:tp][0];
tgr.delegate = // tap delegating
NSPredicate *pp = [NSPredicate predicateWithFormat:@"self isKindOfClass: %@", [UIPanGestureRecognizer class]];
UIPanGestureRecognizer *pgr = (UIPanGestureRecognizer *)[self.pageViewController.view.gestureRecognizers filteredArrayUsingPredicate:pp][0];
pgr.delegate = // pan delegating
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
CGPoint touchPoint = [touch locationInView:self.view];
if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) && touchPoint.y & 915 ) {
return NO; // if y & 915 px in portrait mode
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) && touchPoint.y & 680 ) {
return NO; // if y & 680 px in landscape mode
return YES;
完美的工作:)
只是在你的RootViewController的创建一个子视图(链接到新的IBOutlet gesturesView),并指派手势这个新的观点。这种观点掩盖你想要的手势使屏幕的一部分。
在viewDidLoad中的变化:
self.view.gestureRecognizers=self.pageViewController.gestureR
self.gesturesView.gestureRecognizers=self.pageViewController.gestureR
这是工作最好的,我试过是好的JRAMER答案除了登天(-1页或23页分页时,我会得到一个错误的解决方案
PatMCG的解决方案并没有足够的灵活性,因为它取消了所有的taprecognizers,我仍然希望水tap,但不是我的标签内
在我的UILabel我直接无视如下,这个水tap取消对我的唯一标签
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
return NO;
return YES;
瑞安Heitner解决方案完美的作品。你可以灵活地禁用gesturesRecognizer只对某些观点。你可以把它激活UIPageViewController和网页他人禁用。很酷的解决方案。考虑具有多个页面的应用程序,并在其中一人你想有吸引你的手指无需页面变化的能力。
本文标题 :UIPageViewController手势识别
本文地址 :CodeGo.net/367807/
Copyright (C) 2017 CodeGo.netUITableView与UIPageViewController的UIPanGestureRecognizer手势冲突解决办法 - 零度的浪漫 - ITeye博客
博客分类:
最近在项目中使用了UIPageViewController来翻页,在VIEW上又使用了UITableView,两者都有一个UIPanGestureRecognizer手势,在UITableView上托动的时候两者都接收到了这个UIPanGestureRecognizer手势,
这样的话,会导致手势混乱。解决思路:当触发一个UIPanGestureRecognizer手势的时候,另外一个不响应。这样就不冲突了。
直接上代码解决代码啦,记录一下UIPageViewController的旅程。
第一步:设置UIPageViewController的手势委托
self.view.gestureRecognizers = self.pageViewCtrl.gestureR
for (UIGestureRecognizer* recognizer in self.pageViewCtrl.gestureRecognizers) {
recognizer.delegate=
第二步:利用-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
来解决冲突。
#pragma mark resolve UITableView and UIPageViewController panGesture Conflict
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] &&
[otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
return NO;
return NO;
浏览: 120289 次
来自: 广州
这里有iText 5.5导出pdf, 比较常用的功能及表格画斜 ...
您好,我情况和您一样,然后我按照这个方式做了之后,没有效果,还 ...
这个jar 包 和 这代码里面的类 不一致了,楼主 能改一下吗 ...
写的好。。。
写的好。。。实例讲解iOS中的UIPageViewController翻页视图控制器
作者:珲少
字体:[ ] 类型:转载 时间:
UIPageViewController更像是一个视图容器,将每页不同的ViewController整合,这里我们将以实例讲解iOS中的UIPageViewController翻页视图控制器:
UIPageViewController是iOS中少见的动画视图控制器之一,通过它既可以创建类似UIScrollView与UIPageControl结合的滚屏视图,也可以创建类似图书效果的炫酷翻页视图。
UIPageViewController在iOS 5 SDK中首次引入,它使得开发者可以使用这个ViewController创建分页视图。在iOS 6中,这个类有了更新,支持滚动过渡效果。使用Page View,用户可以方便的通过手势在多个页面之间导航。UIPageViewController并不仅仅用于引导页,很多游戏,例如:愤怒的小鸟,就是用Page View来展示关卡选择的页面,还有有关书籍的应用,用这个类来显示书的页面。
UIPageViewController是个高度可配置的类,你可以进行如下配置:
分页的方向——水平或垂直
翻页的样式——书卷翻页或者滑动翻页
书脊位置——只有书卷翻页样式有效
页面间距——只有滑动翻页样式有效,用来定义页面间距(inter-page spacing)
UIPageViewController类似一个视图容器,其中每个具体的视图由各自的ViewController进行维护管理,UIPageViewController只进行协调与动画布置。下图可以很好的展现出UIPageViewControlelr的使用结构:
上图中,UIPageViewControllerDataSource协议为UIPageViewController提供数据支持,DataSource协议提供的数据来自各个ViewContoller自行维护,UIPageViewControllerDelegate中的回调可以对翻页动作,屏幕旋转动作等进行监听。UIPageViewController把从DataSource中获取到的视图数据渲染给View用于当前视图控制器的展示。
为了演示,我们会一起创建一个简单的app。当然,我们不会演示所有的UIPageViewController的配置细节,我们会演示到使用滑动翻页样式来创建一个引导页。不过别担心,有了对UIPageViewController的基本理解,我相信你能够去探索其他的特性。
二、创建一个UIPageViewController
首先新建一个类作为翻页视图控制器中具体每一页视图的控制器,使其继承于UIViewController:
ModelViewController.h
#import &UIKit/UIKit.h&
@interface ModelViewController : UIViewController
+(ModelViewController *)creatWithIndex:(int)
@property(nonatomic,strong)UILabel * indexL
ModelViewController.m
#import "ModelViewController.h"
@interface ModelViewController ()
@implementation ModelViewController
+(ModelViewController *)creatWithIndex:(int)index{
&&& ModelViewController * con = [[ModelViewController alloc]init];
&&& con.indexLabel = [[UILabel alloc]initWithFrame:CGRectMake(110, 200, 100, 30)];
&&& con.indexLabel.text = [NSString stringWithFormat:@"第%d页",index];
&&& [con.view addSubview:con.indexLabel];
- (void)viewDidLoad {
&&& [super viewDidLoad];
&&& // Do any additional setup after loading the view.
&&& self.view.backgroundColor = [UIColor redColor];
在工程模板自带的ViewController.m文件中实现如下代码:
#import "ViewController.h"
#import "ModelViewController.h"
//遵守协议
@interface ViewController ()&UIPageViewControllerDataSource,UIPageViewControllerDelegate&
&&& //翻页视图控制器对象
&&& UIPageViewController * _pageViewC
&&& //数据源数组
&&& NSMutableArray * _dataA
@implementation ViewController
- (void)viewDidLoad {
&&& [super viewDidLoad];
&&& //进行初始化
&&& _pageViewControl = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{UIPageViewControllerOptionSpineLocationKey:@0,UIPageViewControllerOptionInterPageSpacingKey:@10}];
&&& self.view.backgroundColor = [UIColor greenColor];
&&& //设置翻页视图的尺寸
&&& _pageViewControl.view.bounds=self.view.
&&& //设置数据源与代理
&&& _pageViewControl.dataSource=
&&& _pageViewControl.delegate=
&&& //创建初始界面
&&& ModelViewController * model = [ModelViewController creatWithIndex:1];
&&& //设置初始界面
&&& [_pageViewControl setViewControllers:@[model] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
&&& //设置是否双面展示
&&& _pageViewControl.doubleSided = NO;
&&& _dataArray = [[NSMutableArray alloc]init];
&&& [_dataArray addObject:model];
&&& [self.view addSubview:_pageViewControl.view];
//翻页控制器进行向前翻页动作 这个数据源方法返回的视图控制器为要显示视图的视图控制器
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
&&& int index = (int)[_dataArray indexOfObject:viewController];
&&& if (index==0) {
&&& }else{
&&&&&&& return _dataArray[index-1];
//翻页控制器进行向后翻页动作 这个数据源方法返回的视图控制器为要显示视图的视图控制器
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
&&& int index = (int)[_dataArray indexOfObject:viewController];
&&& if (index==9) {
&&& }else{
&&&&&&& if (_dataArray.count-1&=(index+1)) {
&&&&&&&&&&& return _dataArray[index+1];
&&&&&&& }else{
&&&&&&&&&&& ModelViewController * model = [ModelViewController creatWithIndex:index+2];
&&&&&&&&&&& [_dataArray addObject:model];
&&&&&&&&&&&
//屏幕旋转触发的代理方法
- (UIPageViewControllerSpineLocation) pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation{
&&& return UIPageViewControllerSpineLocationM
//设置分页控制器的分页数
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
&&& return 10;
//设置初始的分页点
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController{
&&& return 0;
上面创建了最简单的翻页视图控制器示例,效果如下图:
三、UIPageViewController中方法使用解析
//创建翻页视图控制器对象
- (instancetype)initWithTransitionStyle:(UIPageViewControllerTransitionStyle)style navigationOrientation:(UIPageViewControllerNavigationOrientation)navigationOrientation options:(nullable NSDictionary&NSString *, id& *)
上面方法用于创建视图控制器对象,其中UIPageViewControllerTransitionStyle参数设置翻页控制器的风格,枚举如下:
typedef NS_ENUM(NSInteger, UIPageViewControllerTransitionStyle) {
&&& UIPageViewControllerTransitionStylePageCurl = 0, //类似于书本翻页效果
&&& UIPageViewControllerTransitionStyleScroll = 1 // 类似于ScrollView的滑动效果
如果设置为UIPageViewControllerTransitionStyleCurl,翻页效果如下图所示:
上面初始化方法中的UIPageViewControllerNavigationOrientation属性设置翻页的方向,枚举如下:
typedef NS_ENUM(NSInteger, UIPageViewControllerNavigationOrientation) {
&&& UIPageViewControllerNavigationOrientationHorizontal = 0,//水平翻页
&&& UIPageViewControllerNavigationOrientationVertical = 1//竖直翻页
options参数用于设置翻页视图控制器的配置字典,其可以设置的配置键值如下:
//这个键需要设置为UIPageViewControllerOptionSpineLocationKey枚举值对应的NSNumber对象 设置翻页控制器的书轴 后面会介绍
NSString * const UIPageViewControllerOptionSpineLocationK
//这个键需要设置为NSNumber类型 设置每页视图的间距 用于滚动视图风格的
NSString * const UIPageViewControllerOptionInterPageSpacingK
下面是UIPageViewController的一些常用属性与方法:
//设置数据源
@property (nullable, nonatomic, weak) id &UIPageViewControllerDelegate&
//设置代理
@property (nullable, nonatomic, weak) id &UIPageViewControllerDataSource& dataS
//获取翻页风格
@property (nonatomic, readonly) UIPageViewControllerTransitionStyle transitionS
//获取翻页方向
@property (nonatomic, readonly) UIPageViewControllerNavigationOrientation navigationO
//获取书轴类型
@property (nonatomic, readonly) UIPageViewControllerSpineLocation spineL
//设置是否双面显示
@property (nonatomic, getter=isDoubleSided) BOOL doubleS
//设置要显示的视图控制器
- (void)setViewControllers:(nullable NSArray&UIViewController *& *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^ __nullable)(BOOL finished))
上面只有spineLocation属性有些难于理解,其枚举如下:
typedef NS_ENUM(NSInteger, UIPageViewControllerSpineLocation) {
&&& //对于SCrollView类型的滑动效果 没有书轴 会返回下面这个枚举值
&&& UIPageViewControllerSpineLocationNone = 0,
&&& //以左边或者上边为轴进行翻转 界面同一时间只显示一个View
&&& UIPageViewControllerSpineLocationMin = 1,&
&&& //以中间为轴进行翻转 界面同时可以显示两个View
&&& UIPageViewControllerSpineLocationMid = 2,
&&& //以下边或者右边为轴进行翻转 界面同一时间只显示一个View
&&& UIPageViewControllerSpineLocationMax = 3&&
将上面的示例代码修改几个地方如下:
- (void)viewDidLoad {
&&& [super viewDidLoad];
&&& // Do any additional setup after loading the view, typically from a nib.
&&& _pageViewControl = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationVertical options:@{UIPageViewControllerOptionSpineLocationKey:@2,UIPageViewControllerOptionInterPageSpacingKey:@10}];
&&& self.view.backgroundColor = [UIColor greenColor];
&&& _pageViewControl.view.bounds=self.view.
&&& _pageViewControl.dataSource=
&&& _pageViewControl.delegate=
&&& ModelViewController * model = [ModelViewController creatWithIndex:1];
&&& ModelViewController * model2 = [ModelViewController creatWithIndex:2];
&&& [_pageViewControl setViewControllers:@[model,model2] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
&&& _pageViewControl.doubleSided = YES;
&&& _dataArray = [[NSMutableArray alloc]init];
&&& [_dataArray addObject:model];
&&& [self.view addSubview:_pageViewControl.view];
- (UIPageViewControllerSpineLocation) pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation{
&&& return UIPageViewControllerSpineLocationM
运行效果如下图所示:
四、UIPageViewControllerDataSource中方法解析
//向前翻页展示的ViewController
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewC
//向后翻页展示的ViewController
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewC
//设置分页控制器的分页点数
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0);
//设置当前分页控制器所高亮的点
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0);
五、UIPageViewControllerDelegate中方法解析
//翻页视图控制器将要翻页时执行的方法
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray&UIViewController *& *)pendingViewControllers NS_AVAILABLE_IOS(6_0);
//翻页动画执行完成后回调的方法
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray&UIViewController *& *)previousViewControllers transitionCompleted:(BOOL)
//屏幕防线改变时回到的方法,可以通过返回值重设书轴类型枚举
- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具UIPageViewController-浅析
一、UIPageViewController概念
控件为我们提供了一种像翻书效果的一种控件。我们可以通过使用UIPageViewController控件,来完成类似图书一样的翻页控制方式。
二、使用UIPageViewController控件
先假象一下,一本书大概可以分为:1.每一页。2.每一页中相应的数据。
使用UIPageViewController控件,也是类似的两个构成部分。要有一个书的框架,来控制页;每一页的内容。
1.创建一个ViewController,包含一个UIPageViewController来控制显示,一个NSArray包括所有数据。
定义这个ViewController类,并使用UIPageViewController来管理每一页,并提供数据。
PageAppViewController.h&
@interface PageAppViewController :
UIViewController&&/span&UIPageViewControllerDataSource&{
@property (strong, nonatomic) UIPageViewController *pageC
@property (strong, nonatomic) NSArray *pageC
PageAppViewController.m
"PageAppViewController.h"
"MoreViewController.h"
@interface
PageAppViewController ()
@implementation
PageAppViewController
@synthesize
pageContent=_pageC
@synthesize
pageController=_pageC
(void)dealloc{
[_pageContent release];
[_pageController release];
& & [super dealloc];
(id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle
*)nibBundleOrNil
& & self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
& & if (self) {
& & // Custom
initialization
& return self;
(void)viewDidLoad
viewDidLoad];
[self createContentPages];//
初始化所有数据
& // 设置UIPageViewController的配置项
& NSDictionary *options =[NSDictionary
dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin]
UIPageViewControllerOptionSpineLocationKey];
& // 实例化UIPageViewController对象,根据给定的属性
& self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options: options];
& // 设置UIPageViewController对象的代理&
& _pageController.dataSource = self;
& // 定义“这本书”的尺寸
[[_pageController
view] setFrame:[[self
view] bounds]];
& // 让UIPageViewController对象,显示相应的页数据。
& // UIPageViewController对象要显示的页数据封装成为一个NSArray。
& // 因为我们定义UIPageViewController对象显示样式为显示一页(options参数指定)。
如果要显示2页,NSArray中,应该有2个相应页数据。
& & MoreViewController *initialViewController
=[self viewControllerAtIndex:0];//
得到第一页
& & NSArray *viewControllers =[NSArray arrayWithObject:initialViewController];
& & [_pageController setViewControllers:viewControllers
& direction:UIPageViewControllerNavigationDirectionForward
& animated:NO
completion:nil];
& // 在页面上,显示UIPageViewController对象的View
addChildViewController:_pageController];
[[self view] addSubview:[_pageController view]];
初始化所有数据
(void) createContentPages {
& NSMutableArray *pageStrings = [[NSMutableArray
alloc] init];
& & for (int i = 1; i & 11; i++){
& & NSString *contentString = [[NSString alloc]
initWithFormat:@"
Chapter %d
This is the page %d of content displayed using
UIPageViewController in iOS 5.
& [pageStrings addObject:contentString];
& & self.pageContent = [[NSArray alloc] initWithArray:pageStrings];
(void)didReceiveMemoryWarning
didReceiveMemoryWarning];
& // Dispose of any resources that can be
recreaviewControllerAtIndexed.
得到相应的VC对象
(MoreViewController
*)viewControllerAtIndex:(NSUInteger)index {
& & if (([self.pageContent count] == 0) || (index &= [self.pageContent count])) {
创建一个新的控制器类,并且分配给相应的数据
& MoreViewController *dataViewController =[[MoreViewController
alloc] init];
dataViewController.dataObject
=[self.pageContent objectAtIndex:index];
& & return dataViewC
根据数组元素值,得到下标值
(NSUInteger)indexOfViewController:(MoreViewController
*)viewController {
& & return [self.pageContent indexOfObject:viewController.dataObject];
#pragma mark- UIPageViewControllerDataSource
// 返回上一个ViewController对象
(UIViewController
*)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController{
& & NSUInteger index = [self indexOfViewController:(MoreViewController *)viewController];
& & if ((index == 0) || (index == NSNotFound)) {
& & index--;
& // 返回的ViewController,将被添加到相应的UIPageViewController对象上。
& // UIPageViewController对象会根据UIPageViewControllerDataSource协议方法,自动来维护次序。
& // 不用我们去操心每个ViewController的顺序问题。
& return [self
viewControllerAtIndex:index];
// 返回下一个ViewController对象
(UIViewController
*)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController{
& & NSUInteger index = [self indexOfViewController:(MoreViewController *)viewController];
& & if (index == NSNotFound) {
& & index++;
& & if (index == [self.pageContent count]) {
& return [self
viewControllerAtIndex:index];
2.声明页对象,来根据UIPageViewController的调度来显示相应页内容。
MoreViewController.h
@interface MoreViewController :
UIViewController&&/span&UIWebViewDelegate&{
@property (nonatomic,
retain) UIWebView *myWebV
@property (nonatomic,
retain) id dataO
MoreViewController.m
"MoreViewController.h"
@implementation
MoreViewController
@synthesize
myWebView=_myWebV
@synthesize
dataObject=_dataO
(id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle
*)nibBundleOrNil
& & self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
& & if (self) {
& & // Custom
initialization
& return self;
(void)dealloc{
[_myWebView release];
& & [super dealloc];
(void) loadView{
& & [super loadView];
& self.myWebView =
[[UIWebView alloc]
initWithFrame:self.view.bounds];
(void)viewDidLoad{
viewDidLoad];
viewWillAppear:(BOOL)paramAnimated{
& & [super viewWillAppear:paramAnimated];
[self.myWebView loadHTMLString:_dataObject baseURL:nil];
& & [self.view addSubview:self.myWebView];
viewWillDisappear:(BOOL)paramAnimated{
所有代码都已经写完了。其中也,写了相关的备注。
着重了解一下关键代码:
1.UIPageViewControllerDataSource协议
该协议主要有两个方法:
(UIViewController
*)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewC
(UIViewController
*)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewC
分别,用来提供UIPageViewController对象的数据源。也就是说,UIPageViewController对象通过该方法来调度显示的内容。
当然,别忘了设置:
_pageController.dataSource&=&self;
2.初始化时,显示适当内容
MoreViewController&*initialViewController
=[self&viewControllerAtIndex:0];//&得到第一页
& &&NSArray&*viewControllers
=[NSArray&arrayWithObject:initialViewController];
&&[_pageController&setViewControllers:viewControllers
&&direction:UIPageViewControllerNavigationDirectionForward
&&animated:NO
&&completion:nil];
&&//&在页面上,显示UIPageViewController对象的View
&&[self&addChildViewController:_pageController];
&&[[self&view]&addSubview:[_pageController&view]];
3.数据必须先准备好。
[self createContentPages];//
初始化所有数据
希望对你有所帮助!
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 linux 内存消耗 的文章

 

随机推荐