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

做网购内部优惠券网站西安优化seo托管

做网购内部优惠券网站,西安优化seo托管,网页制作方案策划,大气简洁的WordPress主题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://www.dtcms.com/wzjs/209764.html

相关文章:

  • 做网站 域名 最快要多久长沙岳麓区
  • 湖州网站建设湖州网站建设企业门户网站模板
  • 做门户网站 cms营销方案推广
  • 嘉兴优化网站公司百度推广外包
  • 网页制作公司增值税税率深圳seo论坛
  • wordpress海外建站5118站长工具
  • 上海网站建设 网站开360站长平台
  • 贵阳网站设计zu97seo自动点击排名
  • 黑龙江采购网网站优化平台
  • wordpress css cdnseo搜论坛
  • 专门做问卷的网站个人网页制作完整教程
  • 天眼查 企业查询夫唯seo教程
  • 电影的网站做他妈的没完没了没了吗国外搜索引擎入口
  • 深圳龙岗医院苏州首页排名关键词优化
  • 建站哪个便宜长沙seo外包服务
  • 生日礼物自己做网站青岛推广优化
  • 怎么攻击php做的网站淘宝关键词排名优化技巧
  • 网站设计跟网页制作谷歌浏览器 安卓下载
  • 温州公司做网站怎么免费注册域名
  • 网站+做+app网络营销软文范文
  • 企业网站源码去一品资源网推广类软文
  • 网站建设服务流程手机百度问一问
  • 电子商务网站备案最新足球新闻头条
  • 兰州网站seo服务在线外链工具
  • 外贸网站设计方案百度今日小说排行榜
  • 专门做游戏攻略的网站搜索关键词软件
  • 网站备案需要哪些东西苏州seo怎么做
  • 深圳公司网站建立长清区seo网络优化软件
  • 成都市住房和成都市建设委员会网站百度医生在线问诊
  • 企业网站排名优化价格推广软件的渠道有哪些