当前位置: 首页 > wzjs >正文

兰州做网站企业金色网站模板

兰州做网站企业,金色网站模板,门户网站做啥,专门做视频的网站有哪些UIPageViewController学习 前言创建一个UIPageViewController最简单的使用 UIPageViewController的方法说明:效果展示 UIPageViewController的协议方法 前言 笔者最近在写项目时想实现一个翻书效果,上网学习到了UIPageViewController今天写本篇博客总结…

UIPageViewController学习

  • 前言
  • 创建一个UIPageViewController
    • 最简单的使用
  • `UIPageViewController`的方法说明:
    • 效果展示
  • `UIPageViewController`的协议方法

前言

笔者最近在写项目时想实现一个翻书效果,上网学习到了UIPageViewController今天写本篇博客总结一下关于该控制器的学习,这里笔者学习较浅,后期再进行补充。下面我给出一张图来展现UIPageViewController的使用结构:
在这里插入图片描述

创建一个UIPageViewController

最简单的使用

首先新建一个类作为翻页视图控制器中具体的每一页视图控制器,使其继承与UIViewController :
ModelViewController类

#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interface ModelViewController : UIViewController
+(ModelViewController *)creatWithIndex:(int)index;
@property(nonatomic,strong)UILabel * indexLabel;@end
NS_ASSUME_NONNULL_END#prama mark - ModelViewController.m#import "ModelViewController.h"
@interface ModelViewController ()
@end
@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];return con;
}这个方法调用时就会增加一个页面。
- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor redColor];
}
@end

***ViewControlller类:

#import "PageViewController.h"@interface PageViewController () <UIPageViewControllerDelegate, UIPageViewControllerDataSource>
@property (nonatomic, strong) UIPageViewController* pageViewControl;
@property (nonatomic, strong) NSMutableArray* dataArray;
@end@implementation PageViewController
- (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.bounds;//设置数据源与代理_pageViewControl.dataSource=self;_pageViewControl.delegate=self;//创建初始界面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) {return nil;}else{return _dataArray[index-1];}
}
//翻页控制器进行向后翻页动作 这个数据源方法返回的视图控制器为要显示视图的视图控制器
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{int index = (int)[_dataArray indexOfObject:viewController];if (index==9) {return nil;}else{if (_dataArray.count - 1 >= (index + 1)) {return _dataArray[index + 1];}else{ModelViewController * model = [ModelViewController creatWithIndex:index + 2];[_dataArray addObject:model];return model;}}
}
//屏幕旋转触发的代理方法
- (UIPageViewControllerSpineLocation) pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation{return UIPageViewControllerSpineLocationMin;
}
//设置分页控制器的分页数
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {return 10;
}
//设置初始的分页点
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController{return 0;
}
@end

效果图:
在这里插入图片描述

  • UIPageViewControllerNavigationOrientationHorizontal:指定为水平滑动,还可以使用UIPageViewControllerNavigationOrientationVertical来进行竖直滑动。

UIPageViewController的方法说明:


//设置数据源
@property (nullable, nonatomic, weak) id <UIPageViewControllerDelegate> delegate;
//设置代理
@property (nullable, nonatomic, weak) id <UIPageViewControllerDataSource> dataSource;
//获取翻页风格
@property (nonatomic, readonly) UIPageViewControllerTransitionStyle transitionStyle;
//获取翻页方向
@property (nonatomic, readonly) UIPageViewControllerNavigationOrientation navigationOrientation;
//获取书轴类型
@property (nonatomic, readonly) UIPageViewControllerSpineLocation spineLocation;
//设置是否双面显示
@property (nonatomic, getter=isDoubleSided) BOOL doubleSided;
  1. 翻页风格:
typedef NS_ENUM(NSInteger, UIPageViewControllerTransitionStyle) {UIPageViewControllerTransitionStylePageCurl = 0, // 类似于滚动视图翻页效果UIPageViewControllerTransitionStyleScroll = 1 // 类似于书本翻页效果
};
  1. 翻页方向
typedef NS_ENUM(NSInteger, UIPageViewControllerNavigationOrientation) {UIPageViewControllerNavigationOrientationHorizontal = 0,//水平翻页UIPageViewControllerNavigationOrientationVertical = 1//竖直翻页
};
  1. spineLocation
typedef NS_ENUM(NSInteger, UIPageViewControllerSpineLocation) {//对于SCrollView类型的滑动效果 没有书轴 会返回下面这个枚举值UIPageViewControllerSpineLocationNone = 0, //以左边或者上边为轴进行翻转 界面同一时间只显示一个ViewUIPageViewControllerSpineLocationMin = 1,  //以中间为轴进行翻转 界面同时可以显示两个ViewUIPageViewControllerSpineLocationMid = 2, //以下边或者右边为轴进行翻转 界面同一时间只显示一个ViewUIPageViewControllerSpineLocationMax = 3   
};

- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;方法详解
这个方法是用于以编程方式切换当前显示的页面,下面讲解一下他的参数:

  • viewControllers:传入的视图控制器,通常只传入一个(当且仅当spineLocation为UIPageViewControllerSpineLocationMid的时候需要传入两个控制器,即书脊效果下)
  • direction:控制页面的动画方向,上述参数中已讲解过。
  • completion:动画完成后的回调,可以更新UI等内容。

效果展示

通过上述方法的使用,我们可以画一个纸张翻页的效果,下面给出示例代码:
我们仅需要更改ViewController中的内容即可:

- (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.bounds;_pageViewControl.dataSource=self;_pageViewControl.delegate=self;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 UIPageViewControllerSpineLocationMid;//仅在当前状态下,一张可以展示两个控制器
}

效果图请添加图片描述

UIPageViewController的协议方法

//向前翻页展示的ViewController
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController;
//向后翻页展示的ViewController
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController;
//设置分页控制器的分页点数
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0);
//设置当前分页控制器所高亮的点
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0);//翻页视图控制器将要翻页时执行的方法
- (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)completed;
//屏幕防线改变时回到的方法,可以通过返回值重设书轴类型枚举
- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation;

总结
关于UIPageViewController笔者还有很多地方没有弄懂,对于其使用也仅仅局限于使用其实现仿真翻页效果,后期笔者还会补充其中内容。个人认为可以使用其实现无限轮播效果,并且更为简单方便,后期会尝试来实现一下。


文章转载自:

http://k35fqZ1E.dtnzk.cn
http://ssOLgbPm.dtnzk.cn
http://pLIIGcfv.dtnzk.cn
http://OHqM1VpI.dtnzk.cn
http://0v3vRAPP.dtnzk.cn
http://15Ac7fGU.dtnzk.cn
http://ZAQUzSVO.dtnzk.cn
http://w635lBzV.dtnzk.cn
http://iEOn2Lki.dtnzk.cn
http://g8BJ18oX.dtnzk.cn
http://Rh07w0nl.dtnzk.cn
http://QvuiaAlj.dtnzk.cn
http://EJO81Vrq.dtnzk.cn
http://FsARUJAR.dtnzk.cn
http://z0tSE0F4.dtnzk.cn
http://5m2xUNJ4.dtnzk.cn
http://UwqwFnwO.dtnzk.cn
http://2LS0wi1B.dtnzk.cn
http://A5gWVocJ.dtnzk.cn
http://zCOlLPfM.dtnzk.cn
http://MBODWmvO.dtnzk.cn
http://aRacaz6u.dtnzk.cn
http://5t6GOjbN.dtnzk.cn
http://ts4wwUuX.dtnzk.cn
http://DFH3vwY1.dtnzk.cn
http://vo8kNSel.dtnzk.cn
http://DSAxVpN7.dtnzk.cn
http://mqQSFVXu.dtnzk.cn
http://79Xn3EmG.dtnzk.cn
http://G0IOI7Hs.dtnzk.cn
http://www.dtcms.com/wzjs/732618.html

相关文章:

  • 营销型网站建设公司提供网站建设网站导航设计欣赏
  • vr成品网站源码在线观看中国建设银行人才招聘官方网站
  • 网站建设语言都有什么软件国网电子商务平台官网
  • 软件设计工作室网站wordpress建站费用
  • 莞城微信网站建设网站举报在哪举报
  • 大学生网站作品c网站开发
  • c语言 做网站网站开发工程师就业形势
  • 南通市规划建设局网站wordpress评论删除
  • 某网站开发项目成本估计拼多多app官方下载
  • seo网站怎么做网站建站网站设计公司
  • 网站建设做微营销网页设计代码大全
  • 网站建设教学后记免费建社交网站
  • 网站建设公司推荐乐云seo竞价网站和优化网站的区别
  • 照片分享网站模板下载门户网站建设投入
  • 天津做宠物饲料的网站嵌入式开发难学吗
  • 云vps怎么搭建网站让wordpress自检
  • 网站建设要用多少种字体焦作网站建设jz518
  • 怎么认证网站重庆最好的网站建设公司
  • 网站侧栏设计logo字体设计在线生成
  • 北京做网站公司哪家好做社交网站框架
  • 厦门网站建设求职简历WordPress文章百度收录插件
  • 政务服务 网站 建设方案英国小子做房产网站
  • 电脑上做简单的网站济宁网架公司
  • 火速网站建设wordpress站内链接跳转
  • 网站建设项目前景湘西网站建设吧
  • 如何建立asp网站公司注册的流程和条件
  • 什么网站做h5好wordpress二次开发视频
  • wordpress适合任务网站吗白之家低成本做网站
  • 福田企业网站优化哪个好阿里云腾讯云网站建设
  • 国外设计作品网站搜狗网站提交