如何在UICollectionView中使用useLayoutToLayoutNavigationTransitions? [英] How to use useLayoutToLayoutNavigationTransitions in UICollectionView?

查看:542
本文介绍了如何在UICollectionView中使用useLayoutToLayoutNavigationTransitions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在iOS7集合视图中学习新的布局过渡效果。

I was trying to learn the new layout transition effect in iOS7 collection view.

然而,我根本无法让它工作。我在下面附上了一个屏幕截图说明。

However, I am unable to get it to work at all. I have attached a screen shot description below.

我知道当此Transition效果生效时,控制器之间使用相同的Collection View。但是,为什么在转换发生时该集合视图不会重新加载。我甚至尝试重新加载集合视图太失败了。

I am aware that the same Collection View is used between Controllers when this Transition effect is in effect. But, why that collection view is not reloading when transition is happening. I even tried Reloading the collection view an that too failed.

应该有一些简单的观点我应该遗漏。请帮帮我。

There should be some simple point I should be missing. Help me please.

我附上了以下源代码。

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(75.0, 70.0);

    ALCollectionViewNoXibController* controller = [[ALCollectionViewNoXibController alloc] initWithCollectionViewLayout:flowLayout];
    controller.numberOfItems = _numberOfItems-1;
controller.transitionType = _transitionType;
    if (_transitionType == kLayoutTransition) {
        controller.useLayoutToLayoutNavigationTransitions = YES;
    }
   [self.navigationController pushViewController:controller animated:YES];

项目代码

推荐答案

新的您正在加载的flowLayout 确实正在使用。你可以看到它,例如,你做 flowLayout.itemSize = CGSizeMake(10.0 * _numberOfItems,10.0 * _numberOfItems);

The new flowLayout that you are loading is indeed being used. You can see it if for instance, you do flowLayout.itemSize = CGSizeMake(10.0*_numberOfItems, 10.0*_numberOfItems);

您的问题是,为了使转换工作,iOS将在动画过渡期间更改您的数据源

Your issue is that in order to make the transition work, iOS will change your datasource during the animated transition.

试试这个:

让你的班级成为导航代表:

Make your class a Navigation delegate:

@interface ALCollectionViewNoXibController ()<UINavigationControllerDelegate>

然后在推送之前将导航的代理设置为当前控制器

Then set the delegate of the navigation to the current controller, before pushing

self.navigationController.delegate = self;
[self.navigationController pushViewController:controller animated:YES];

现在你可以添加

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

   ALCollectionViewNoXibController *controller = (ALCollectionViewNoXibController *)viewController;
   navigationController.delegate = controller;
   controller.collectionView.dataSource = controller;
}

当你导航回顶层控制器时,这个简单的例子将会中断,因为收到的viewController不是 ALCollectionViewNoXibController 类。但是你明白了。

This simple example will break when you navigate back to the top controller, because the viewController received is not of ALCollectionViewNoXibController class. But you get the idea.

这篇关于如何在UICollectionView中使用useLayoutToLayoutNavigationTransitions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆