老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)

怎么在iOS中利用pageViewController實現(xiàn)多視圖滑動切換

本篇文章為大家展示了怎么在iOS中利用pageViewController實現(xiàn)多視圖滑動切換,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了那坡免費建站歡迎大家使用!

思路1:使用嵌套,collectionview嵌套,每個item中添加內(nèi)容

思路2:使用scrollview 在上面創(chuàng)建一個一個的controller 實現(xiàn)左右滑動

當(dāng)停留在第一頁的時候,點擊標(biāo)題欄第五頁,那么平移的過程就是第一頁到第五頁,所有的頁面從屏幕快速閃過,并且看到現(xiàn)在很多APP都是這樣的。在此之前我是用的思路2,為了避免跨頁面切換出現(xiàn)的中間幾個頁面閃過的過程,直接把平移動畫關(guān)閉了。直到使用了uipageViewController,趕緊把項目中的給換掉了

代碼不多150行以內(nèi)

#import "ViewController.h"http:/// 當(dāng)前controller
#import "MyViewController.h" /// 復(fù)用的controller 適用于每個控制器布局相同的情況下,,布局不同就創(chuàng)建不同的controller添加進(jìn)來
#import "TitleCollectionViewCell.h"http:/// 標(biāo)題欄使用的collectionviewcell

@interface ViewController (){

 //// 記錄當(dāng)前頁 當(dāng)前標(biāo)題位置

 NSInteger ld_currentIndex;

}

@property (nonatomic, strong) UIPageViewController *pageViewController;
@property (nonatomic, strong) NSMutableArray *controllersArr;/// 控制器數(shù)組
@property (nonatomic, strong) NSMutableArray *titleArray; /// 標(biāo)題數(shù)組
@property (nonatomic, strong) UICollectionView *titleCollectionView; /// 標(biāo)題collectionview

@end

@implementation ViewController


- (void)viewDidLoad {
 [super viewDidLoad];
 self.view.backgroundColor = [UIColor whiteColor];
 self.navigationController.navigationBar.translucent = NO;
 self.controllersArr = [NSMutableArray array];
 self.titleArray = [NSMutableArray array];
 //// 如果controller布局相同則循環(huán)創(chuàng)建MyViewController 添加進(jìn)數(shù)組,,如果controller 布局不同 那就創(chuàng)建多個不同controller依次添加數(shù)組
 for (int i = 0; i < 10; i++) {
 MyViewController *con = [[MyViewController alloc]init];
 [self.controllersArr addObject:con];
 NSString *str = [NSString stringWithFormat:@"第 %d 頁", i+1];
 con.titlestring = str;
 [self.titleArray addObject:str];

 }
 [self createCollectionView];
 [self createPageViewController];
 [self setTheFirstPage];

}



/// 創(chuàng)建標(biāo)題collectionview
- (void)createCollectionView{
 UICollectionViewFlowLayout *lay = [[UICollectionViewFlowLayout alloc] init];
 lay.itemSize = CGSizeMake(60, 30);
 lay.minimumLineSpacing = 0;
 lay.minimumInteritemSpacing = 0;
 lay.scrollDirection = UICollectionViewScrollDirectionHorizontal;
 self.titleCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 34, 375, 30) collectionViewLayout:lay];
 self.titleCollectionView.showsHorizontalScrollIndicator = NO;
 self.titleCollectionView.backgroundColor = [UIColor whiteColor];
 self.titleCollectionView.delegate = self;
 self.titleCollectionView.dataSource = self;
 [self.titleCollectionView registerClass:[TitleCollectionViewCell class] forCellWithReuseIdentifier:@"titleReuse"];
 [self.navigationController.view addSubview:self.titleCollectionView];


}

//// 標(biāo)題collectionview的協(xié)議方法

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
 return self.titleArray.count;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
 TitleCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"titleReuse" forIndexPath:indexPath];
 cell.titleLabel.text = self.titleArray[indexPath.row];
 if (indexPath.row == ld_currentIndex) {
 cell.titleLabel.textColor = [UIColor orangeColor];

 }else{

 cell.titleLabel.textColor = [UIColor blackColor];

 }

 return cell;

}

//// 點擊標(biāo)題左右切換視圖控制器------------再也不用看到好幾個中間頁面從屏幕快速閃過了------
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
 UIViewController *vc = [self.controllersArr objectAtIndex:indexPath.row];
 if (indexPath.row > ld_currentIndex) {
 [self.pageViewController setViewControllers:@[vc] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {

 }];

 } else {

 [self.pageViewController setViewControllers:@[vc] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:^(BOOL finished) {

 }];

 }
 ld_currentIndex = indexPath.row;
 NSIndexPath *path = [NSIndexPath indexPathForRow:ld_currentIndex inSection:0];
 [self.titleCollectionView scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
 [self.titleCollectionView reloadData];

}



/// 創(chuàng)建pageViewController
- (void)createPageViewController {
 NSDictionary *option = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:0] forKey:UIPageViewControllerOptionInterPageSpacingKey];
 _pageViewController = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:option];
 _pageViewController.delegate = self;
 _pageViewController.dataSource = self;
 [self addChildViewController:_pageViewController];
 [self.view addSubview:_pageViewController.view];

}

/// 展示上一頁
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
 NSInteger index = [self.controllersArr indexOfObject:viewController];
 if (index == 0 || (index == NSNotFound)) {
 return nil;

 }

 index--;
 return [self.controllersArr objectAtIndex:index];

}

/// 展示下一頁
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
 NSInteger index = [self.controllersArr indexOfObject:viewController];
 if (index == self.controllersArr.count - 1 || (index == NSNotFound)) {
 return nil;

 }

 index++;
 return [self.controllersArr objectAtIndex:index];

}

/// 將要滑動切換的時候
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers {
 UIViewController *nextVC = [pendingViewControllers firstObject];
 NSInteger index = [self.controllersArr indexOfObject:nextVC];
 ld_currentIndex = index;

}

/// 滑動結(jié)束后
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed {
 if (completed) {
 NSIndexPath *path = [NSIndexPath indexPathForRow:ld_currentIndex inSection:0];
 [self.titleCollectionView scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
 [self.titleCollectionView reloadData];

 NSLog(@">>>>>>>>> %ld", (long)ld_currentIndex);

 } 

}

/// 設(shè)置默認(rèn)顯示的是哪個頁面(controller)
- (void)setTheFirstPage{
 UIViewController *vc = [self.controllersArr objectAtIndex:ld_currentIndex];
 [self.pageViewController setViewControllers:@[vc] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];

}

- (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];
 // Dispose of any resources that can be recreated.

}

TitleCollectionViewCell
@implementation TitleCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame{
 self = [super initWithFrame:frame];
 if (self) {
 [self createView];

 }
 return self;

}

- (void)createView{
 self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height)];
 [self.contentView addSubview:self.titleLabel];
 self.titleLabel.font = [UIFont systemFontOfSize:14];

}
@end

上述內(nèi)容就是怎么在iOS中利用pageViewController實現(xiàn)多視圖滑動切換,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


網(wǎng)頁標(biāo)題:怎么在iOS中利用pageViewController實現(xiàn)多視圖滑動切換
URL鏈接:http://www.xueling.net.cn/article/gcches.html

其他資訊

在線咨詢
服務(wù)熱線
服務(wù)熱線:028-86922220
TOP
主站蜘蛛池模板: 国产开嫩苞视频在线观看 | 五月精品夜夜春夜夜爽久久 | 午夜福利啪啪无遮挡免费 | 最近中文字幕mv2018在线高清 | 精品深夜AV无码一区二区老年 | 久久亚洲精品成人无码网站蜜桃 | 欧美在线一 | 国产成人精品影视 | 亚洲综合欧美一区二区在线 | 久久精品成人热国产成 | 日本久久高清一区二区三区毛片 | 日本专区 | 日日操视频 | 程视频精品视频一区二区三区欧 | 精品无码久久午夜福利 | 9999人体做爰大胆视频摄影 | 两个奶头被吃高潮 | 男人操女人高清视频 | 国产大胸A在线观看 | 特级精品毛片免费观看 | 亚洲精品天堂无码中文字幕 | 无码任你躁久久久久久老妇 | 亚洲精品久久久久玩吗 | 成人无码A区在线观看视频 亚洲免费成人在线 | 在线播放免费人成视频网站 | 天天摸天天干 | 大码老熟女xx | 婷婷五月六月综合缴情 | 男人边吻奶边挵进去成人网站 | 日韩欧美国产一区二区三区 | 欧美日韩国产综合在线 | 国产视频精品一区二区三区 | 爱色av| 黄网久久 | 国产91精品入口福利 | 东京热加勒比波多野结衣 | 一区二区三区四区在线看 | 亚洲精品国久久99热 | 波多野结衣在线视频一区二区三区 | 91久久精品国产91久久性色也 | 人人妻一区二区三区 |