Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView更改布局选定项和框架/约束_Ios_Swift_Uicollectionview_Uicollectionviewlayout - Fatal编程技术网

Ios UICollectionView更改布局选定项和框架/约束

Ios UICollectionView更改布局选定项和框架/约束,ios,swift,uicollectionview,uicollectionviewlayout,Ios,Swift,Uicollectionview,Uicollectionviewlayout,我有一个集合视图,在这个视图中,我在一个看起来像UITableView的布局和一个看起来有点像时间机器的旋转木马的布局之间动态切换,我称之为“SwipeLayout”(现在不进行滑动,但最终会) 顺便说一句,整个项目在这里:。在主分支下,标记为“初始问题” 初始布局是表格布局,当点击一个项目时,我将布局更改为带有动画的“SwipeLayout”(然后再次返回)。在我的ViewController中,我有: func collectionView(collectionView: UICollect

我有一个集合视图,在这个视图中,我在一个看起来像UITableView的布局和一个看起来有点像时间机器的旋转木马的布局之间动态切换,我称之为“SwipeLayout”(现在不进行滑动,但最终会)

顺便说一句,整个项目在这里:。在主分支下,标记为“初始问题”

初始布局是表格布局,当点击一个项目时,我将布局更改为带有动画的“SwipeLayout”(然后再次返回)。在我的ViewController中,我有:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    NSLog("index Path chosen: \(indexPath)")
    changeLayoutTapped(self)
}

@IBAction func changeLayoutTapped(sender: AnyObject) {
    if (self.collectionView.collectionViewLayout == tableLayout) {
        self.collectionView.setCollectionViewLayout(swipeLayout, animated: true)
        self.mode = Mode.Swipe
    } else {
        self.collectionView.setCollectionViewLayout(tableLayout, animated: true)
        self.mode = Mode.Table
    }
}
SwipeLayout的代码有点长,所以我不想把它放在这个问题中,但这里有一个链接:

以下是当前过渡的情况:

在大多数情况下,它看起来不错。但是,如果我们在非零的元素上启动抽头,则会发生以下情况:

我不明白为什么它经过转换,然后又恢复到先显示0元素

以下是在sim卡中打开慢速转换后的效果:

我尝试在集合视图上设置所选元素,如下所示:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    NSLog("index Path chosen: \(indexPath)")
    self.swipeLayout.startingItemIndex = indexPath.item
    changeLayoutTapped(self)
}
但是那里没有运气

有什么想法吗

额外的奖金,如果有人能告诉我如何让内容(内部的数字)在整个过渡期间保持在中间的视野。 谢谢