KelvinJin / AnimatedCollectionViewLayout

A UICollectionViewLayout subclass that adds custom transitions/animations to the UICollectionView without effecting your existing code.
MIT License
4.75k stars 351 forks source link

Objective-c compatibility #36

Open CavalcanteLeo opened 6 years ago

CavalcanteLeo commented 6 years ago

I can't use any property in objective-c (eg: layout.animator), none of them are visible.

captura de tela 2018-01-19 as 18 56 47

BaluNaik commented 6 years ago

Create Swift Extension and import into your objective-C class

@objc public extension AnimatedCollectionViewLayout{

@objc class func initWithPageAnimator() -> AnimatedCollectionViewLayout{
    let layout = AnimatedCollectionViewLayout()
    layout.scrollDirection = .horizontal
    layout.animator = PageAttributesAnimator(scaleRate: 0.0)

    layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    layout.minimumInteritemSpacing = 0
    layout.minimumLineSpacing = 0

    return layout
}
@objc class func initWithParallaxAnimator() -> AnimatedCollectionViewLayout{
    let layout = AnimatedCollectionViewLayout()
    layout.scrollDirection = .horizontal
    layout.animator = ParallaxAttributesAnimator(speed: 0.2)

    layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    layout.minimumInteritemSpacing = 0
    layout.minimumLineSpacing = 0

    return layout
}

}

Just use like this

self.collectionView.collectionViewLayout = (AnimatedCollectionViewLayout*)[AnimatedCollectionViewLayout initWithPageAnimator]; }