我尝试使用CSStickyHeaderFlowLayout在我的应用中制作视差照片效果 - https://github.com/jamztang/CSStickyHeaderFlowLayout/ 和斯威夫特语。
我已安装必要的Pod文件,添加#import" CSStickyHeaderFlowLayout.h"到我的" appName" -Bridging-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);
}
在我看来,在那一步之后,我的效果应该有效。我对吗?或者我错过了什么?
感谢您的帮助, m.af
答案 0 :(得分:1)
你应该可以在Swift
中这样做if let layout = self.collectionViewLayout as? CSStickyHeaderFlowLayout {
layout.parallaxHeaderReferenceSize = CGSizeMake(320, 200)
}
答案 1 :(得分:0)
你可以试试这个:
var layout = CSStickyHeaderFlowLayout()
if (layout.isKindOfClass(CSStickyHeaderFlowLayout.self)) {
layout.parallaxHeaderReferenceSize = CGSizeMake(self.view.frame.size.width, 426)
layout.parallaxHeaderMinimumReferenceSize = CGSizeMake(self.view.frame.size.width, 110)
layout.itemSize = CGSizeMake(self.view.frame.size.width, layout.itemSize.height)
layout.parallaxHeaderAlwaysOnTop = true
// If we want to disable the sticky header effect
layout.disableStickyHeaders = true
}