【问题标题】:CSStickyHeaderFlowLayout swiftCSStickyHeaderFlowLayout 快速
【发布时间】: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

【问题讨论】:

标签: objective-c iphone swift ios8 parallax


【解决方案1】:

你应该可以在 Swift 中这样做

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

【讨论】:

    【解决方案2】:

    你可以试试这个:

    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
    }
    

    【讨论】:

      猜你喜欢
      • 2017-02-13
      • 2015-10-17
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-21
      相关资源
      最近更新 更多