【发布时间】:2015-01-18 17:29:50
【问题描述】:
我正在尝试使用 CSStickyHeaderFlowLayout 在我的应用中制作视差照片效果 - https://github.com/jamztang/CSStickyHeaderFlowLayout/ 和 Swift 语言。
我已经安装了必要的 Pod 文件,在我的“appName”-Bridging-Header.h 文件中添加了#import "CSStickyHeaderFlowLayout.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);
}
在我看来,在那一步之后,我的效果应该会起作用。我对吗?还是我错过了什么?
感谢您的帮助, m.af
【问题讨论】:
-
为什么要在 Swift 中使用这么简单的 ObjC 类。你可以重写它或者可能使用我的实现:github.com/bernikovich/StickyHeaderFlowLayout
标签: objective-c iphone swift ios8 parallax