2014-11-20 25 views
1

我想在我的應用程序中使用CSStickyHeaderFlowLayout製作視差照片效果 - https://github.com/jamztang/CSStickyHeaderFlowLayout/ 和Swift語言。CSStickyHeaderFlowLayout swift

我已經安裝了必要的波德的文件中,添加#進口「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

回答

1

你應該能夠做到像這樣在斯威夫特

if let layout = self.collectionViewLayout as? CSStickyHeaderFlowLayout { 
    layout.parallaxHeaderReferenceSize = CGSizeMake(320, 200) 
} 
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 
}