【问题标题】:Animate UICollectionViewLayout header size causes unwanted flash cross dissolve动画 UICollectionViewLayout 标题大小会导致不需要的 flash 交叉溶解
【发布时间】:2017-04-25 21:12:26
【问题描述】:

问题可见:http://i.imgur.com/TastPR9.gifv

func animateHeaderResize(height: CGFloat) {

    let layout = self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout;
    layout.headerReferenceSize = CGSize(width: UIScreen.main.bounds.width, height: height);

    UIView.animate(withDuration: 1, delay: 0, options: .curveEaseOut, animations: {
        self.collectionView?.layoutIfNeeded();
    }) { (finished) in
        //self.loadPosts();
    }
}

我正在尝试通过 UICollectionViewLayout 对 UICollectionView 的标题大小进行动画更改。生成的动画有一个奇怪的闪光和拉伸,可能是某个地方触发了交叉溶解过渡。我尝试了许多设置集合视图布局的变体,包括 setCollectionViewLayout(layout:animated:) 和实现 collectionView(_ collectionView: layout:referenceSizeForHeaderInSection section:),但都产生相同的动画。

我注意到在更改集合视图的项目大小时会出现相同的闪烁。也许这是我可以修改的一些默认行为?我必须继承 UICollectionViewFlowLayout 吗?我已经尝试过搜索,但找不到解决方案,如果朝着正确的方向迈出一步,我将不胜感激。

【问题讨论】:

    标签: ios iphone swift uicollectionview uicollectionviewlayout


    【解决方案1】:

    这最终对我有用:

    func animateHeaderResize(height: CGFloat) {
    
        self.collectionView?.performBatchUpdates({ 
            let layout = self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout;
            layout.headerReferenceSize = CGSize(width: UIScreen.main.bounds.width, height: height);
        }, completion: { (fin) in
            self.loadPosts();
        });
    
    }
    

    【讨论】:

      【解决方案2】:

      看到同样的问题,如果我设置,我可以看到动画看起来更好:

      layout.sectionHeadersPinToVisibleBounds = false
      

      【讨论】:

        猜你喜欢
        • 2013-05-18
        • 1970-01-01
        • 1970-01-01
        • 2021-07-23
        • 1970-01-01
        • 2020-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多