Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not work with swift ? #50

Open
gantoday opened this issue Nov 7, 2015 · 3 comments
Open

does not work with swift ? #50

gantoday opened this issue Nov 7, 2015 · 3 comments

Comments

@gantoday
Copy link

gantoday commented Nov 7, 2015

I have tested BLKFlexibleHeightBar in my project, but it just show no effect.
And i could not find the reason. Could anyone help me? Many thanks!!

my test project repo:
https://github.com/gantoday/BLKFlexibleHeightBar-test

my viewController:

import UIKit
import BLKFlexibleHeightBar


class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let myBar = BLKFlexibleHeightBar(frame: CGRectMake(0.0, 0.0, self.view.frame.size.width, 100.0))
        myBar.minimumBarHeight = 20
        myBar.backgroundColor = UIColor.RedColor()

        myBar.behaviorDefiner = SquareCashStyleBehaviorDefiner()
        myBar.behaviorDefiner.addSnappingPositionProgress(0.0, forProgressRangeStart: 0.0, end: 0.5)
        myBar.behaviorDefiner.addSnappingPositionProgress(1.0, forProgressRangeStart: 0.5, end: 1.0)

        self.tableView.delegate = myBar.behaviorDefiner as? UITableViewDelegate

        self.view.addSubview(myBar)

        self.tableView.contentInset = UIEdgeInsetsMake(myBar.maximumBarHeight, 0.0, 0.0, 0.0);

        let label = UILabel();
        label.text = "hello word"
        label.font = UIFont.systemFontOfSize(25.0)
        label.textColor = UIColor.whiteColor()
        label.sizeToFit()
        myBar.addSubview(label)

        let initialLayoutAttributes = BLKFlexibleHeightBarSubviewLayoutAttributes()
        initialLayoutAttributes.size = label.frame.size
        initialLayoutAttributes.center = CGPointMake(CGRectGetMidX(myBar.bounds), CGRectGetMidY(myBar.bounds) + 10.0)
        label.addLayoutAttributes(initialLayoutAttributes, forProgress: 0.0)


        let finalLayoutAttributes = BLKFlexibleHeightBarSubviewLayoutAttributes(existingLayoutAttributes: initialLayoutAttributes)
        finalLayoutAttributes.alpha = 0.0
        let translation = CGAffineTransformMakeTranslation(0.0, -30.0)
        let scale = CGAffineTransformMakeScale(0.2, 0.2)
        finalLayoutAttributes.transform = CGAffineTransformConcat(scale, translation)
        label.addLayoutAttributes(finalLayoutAttributes, forProgress: 1.0)

    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 30
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 

        return cell

    }

}
@DomiR
Copy link

DomiR commented Dec 8, 2015

self.tableView.delegate = myBar.behaviorDefiner as? UITableViewDelegate was not working for me... optional downcast gave back nil. I made my own delegate splitter that returns UITableViewDelegate.

same as: #42

@harshilkotecha
Copy link

harshilkotecha commented Dec 28, 2017

This is working fine in swift 4 also
add this extension to solve this issue this is work for me

extension BLKFlexibleHeightBarBehaviorDefiner :UITableViewDelegate{
    
}

@gantoday
Copy link
Author

Two years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants