Closed shenguanjiejie closed 6 years ago
如果我把 _pageController.layout.progressAnimateEnabel 设置为NO,那么就会只有第一个Cell的frame是正确的,滑动到另外两个页面,Cell不出现,我用xcode的debug navigator看,确实是有3个cell的,只是另外两个的size永远是{0,0}
demo 发给我看看
@12207480 demo写好了 你看一下 我想要的效果是三个图片本来就一起显示出来,但是现在不行,只能有一个显示出来 https://github.com/shenguanjiejie/TYPagerControllerDemo.git
看这个demo,是不是代理方法必须返回一个遵守TYTabPagerBarCellProtocol协议的CollectionCell有点奇怪了? 不知道能不能去掉这个限制
😂 好吧 是我傻叉了... 关掉了
配置代码如下: ` _tabBar = [[TYTabPagerBar alloc]init]; _tabBar.layout.barStyle = TYPagerBarStyleNoneView; _tabBar.dataSource = self; _tabBar.delegate = self; _tabBar.layout.cellWidth = kScreenWidth / 3; _tabBar.layout.progressHeight = 0; _tabBar.layout.cellSpacing = 0; [_tabBar registerClass:[RJButtonCCell class] forCellWithReuseIdentifier:@"CELL"]; [self.view addSubview:_tabBar];
// pagerController.layout.autoMemoryCache = NO; // 只有当scroll滚动动画停止时才加载pagerview,用于优化滚动时性能 _pageController.layout.addVisibleItemOnlyWhenScrollAnimatedEnd = NO; _pageController.dataSource = self; _pageController.delegate = self; [self addChildViewController:_pageController]; [self.view addSubview:_pageController.view]; `
`
(void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; _tabBar.frame = CGRectMake(0, 0, kScreenWidth, 70); _pageController.view.frame = CGRectMake(0, 70, kScreenWidth, kScreenHeight - 70); }
代理方法如下:
pragma mark - TYTabPagerBarDataSource
(NSInteger)numberOfItemsInPagerTabBar { return 3; }
(UICollectionViewCell )pagerTabBar:(TYTabPagerBar )pagerTabBar cellForItemAtIndex:(NSInteger)index {
UICollectionViewCell cell = [pagerTabBar dequeueReusableCellWithReuseIdentifier:@"CELL" forIndex:index];
RJButtonCCell buttonCell = (RJButtonCCell *)cell;
if (index == 0) { [buttonCell.button setImage:kImageNamed(icon_main_personal_un) forState:UIControlStateNormal]; [buttonCell.button setImage:kImageNamed(icon_main_personal_se) forState:UIControlStateSelected]; }else if (index == 1){ [buttonCell.button setImage:kImageNamed(icon_main_people_un) forState:UIControlStateNormal]; [buttonCell.button setImage:kImageNamed(icon_main_people_se) forState:UIControlStateSelected]; }else{ [buttonCell.button setImage:kImageNamed(icon_main_chat_un) forState:UIControlStateNormal]; [buttonCell.button setImage:kImageNamed(icon_main_chat_se) forState:UIControlStateSelected]; }
return cell; }
pragma mark - TYPagerControllerDataSource
(NSInteger)numberOfControllersInPagerController { return 3; }
(UIViewController )pagerController:(TYPagerController )pagerController controllerForIndex:(NSInteger)index prefetching:(BOOL)prefetching { if (index%3 == 0) { SettingVC VC = [[SettingVC alloc]init]; VC.view.backgroundColor = [UIColor whiteColor]; return VC; }else if (index%3 == 1) { SettingVC VC = [[SettingVC alloc]init]; VC.view.backgroundColor = [UIColor redColor]; return VC; }else { SettingVC *VC = [[SettingVC alloc]init]; VC.view.backgroundColor = [UIColor blueColor]; return VC; } }
pragma mark - TYPagerControllerDelegate
-(void)pagerController:(TYPagerController *)pagerController transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress { [_tabBar scrollToItemFromIndex:fromIndex toIndex:toIndex progress:progress]; } ` 显示效果: