CSStickyHeaderFlowLayout

CSStickyHeaderFlowLayout

我正在尝试使用CSStickyHeaderFlowLayout在我的应用程序中生成视差照片效果
-https://github.com/jamztang/CSStickyHeaderFlowLayout/
语言敏捷。
我已经安装了必要的Pod文件,将“import”CSStickyHeaderFlowLayout.h“添加到我的“appName”-bridge Header.h文件中,并实现了以下方法:

func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {

    var cell: UICollectionViewCell = UICollectionViewCell(frame: CGRectMake(0, 0, 400, 200));
    var imageView: UIImageView = UIImageView();
    var image: UIImage  = UIImage(named: "news2.jpg")!;
    imageView.image = image;
    cell.addSubview(imageView);
    return cell;

}

但现在我很难把这个Obj-C代码翻译成Swift:
CSStickyHeaderFlowLayout *layout = (id)self.collectionViewLayout;
if ([layout isKindOfClass:[CSStickyHeaderFlowLayout class]]) {
    layout.parallaxHeaderReferenceSize = CGSizeMake(320, 200);
}

在我看来,在那一步之后,我的效果应该会起作用。我说得对吗?还是我漏掉了什么?
谢谢你的帮助,
房颤

最佳答案

你应该很快就能做到

if let layout = self.collectionViewLayout as? CSStickyHeaderFlowLayout {
    layout.parallaxHeaderReferenceSize = CGSizeMake(320, 200)
}

关于objective-c - CSStickyHeaderFlowLayout swift ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27046624/

10-12 21:28