ltebean / LTNavigationBar

UINavigationBar Category which allows you to change its appearance dynamically
MIT License
4.46k stars 677 forks source link

TopView is to small #9

Closed steffimueller closed 9 years ago

steffimueller commented 9 years ago

I tried to create your example in code instead of in the storyboard.

In AppDelegate I created:

let vc = Page1ViewController()
window?.rootViewController = UINavigationController(rootViewController: vc)

Page1ViewController is:

@objc(Page1ViewController)
class Page1ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

  let cellIndentifier = "cell"
  let NAVBAR_CHANGE_POINT:CGFloat = 50

  @IBOutlet weak var tableView: UITableView!
  var topView:UIView!
  var topImageView: UIImageView?

  override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "someAction"), animated: true)

    self.tableView.delegate = self
    self.tableView.dataSource = self
    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellIndentifier)
    self.navigationController?.navigationBar.lt_setBackgroundColor(UIColor.clearColor())

    topView = UIView(frame: CGRectMake(0, 0, 320, 212))
    topView.backgroundColor = UIColor.yellowColor()
    tableView.addSubview(topView)

    let img = UIImage(named: "bg2")
    topImageView = UIImageView(image: img)
    topImageView?.frame = CGRectMake(0, -89, 320, 307)
    topImageView?.contentMode = UIViewContentMode.ScaleToFill
    topView.addSubview(topImageView!)

    topView.superview?.sendSubviewToBack(topView)

  }
  ...
}

In the nib of Page1ViewController I just inserted a UITableView and linked the outlet to tableView.

Here is the result when I run the app:

ios_simulator_-_iphone_5_-_iphone_5___ios_7_1__11d167_

It works like your demo app with the exception that the header does not have the correct height. How can I change that?

Thanks for help!

confile commented 9 years ago

+1

steffimueller commented 9 years ago

@ltebean Could you please help me with this issue?

ltebean commented 9 years ago

@steffimueller I guess it is due to the table view position, did you put it behind the navbar or under the navbar? Could you share the entire project to me, since that will make it easy to find out what's wrong with it

steffimueller commented 9 years ago

@ltebean Thanks for help. Here is the project:

https://github.com/steffimueller/LTNavigationBar-TestProject

steffimueller commented 9 years ago

I suppose it is just a small thing. :-)

ltebean commented 9 years ago

just set the topView as the table header view: tableView.tableHeaderView = topView

steffimueller commented 9 years ago

I tried this before like here:

  override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "sdfsdf"), animated: true)

    self.tableView.delegate = self
    self.tableView.dataSource = self
    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellIndentifier)
    self.navigationController?.navigationBar.lt_setBackgroundColor(UIColor.clearColor())

    tableView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleWidth

    topView = UIView(frame: CGRectMake(0, 0, 320, 212))
    topView.contentMode = UIViewContentMode.ScaleToFill
    topView.autoresizesSubviews = true
    topView.backgroundColor = UIColor.yellowColor()
   // topView.clipsToBounds = true

    tableView.tableHeaderView = topView
//    tableView.backgroundView = testView

  //  tableView.addSubview(topView)

    let img = UIImage(named: "bg")
    topImageView = UIImageView(image: img)
    topImageView?.frame = CGRectMake(0, -89, 320, 307)
    topImageView?.contentMode = UIViewContentMode.ScaleToFill
    topView.addSubview(topImageView!)

//    topView.superview?.sendSubviewToBack(topView)

  }

The result is this:

ios_simulator_-_iphone_5_-_iphone_5___ios_7_1__11d167_

The problem is that the first table row is now overlapped by the image. Any idea?

steffimueller commented 9 years ago

I want to get the same result as you did in your parallax branch but just using nib instead of Storyboard.

steffimueller commented 9 years ago

@ltebean I post a bounty on stack overflow may be you can answer that?

http://stackoverflow.com/questions/30130879/uiview-as-top-view-for-uitableview

ltebean commented 9 years ago

@steffimueller please add me to your repo

steffimueller commented 9 years ago

done!

ltebean commented 9 years ago

@steffimueller I pushed, this commit: https://github.com/steffimueller/LTNavigationBar-TestProject/commit/3da723a073e4f9234d0533d32032c4f7610134b1

steffimueller commented 9 years ago

@ltebean Thank you but there is still a difference to the parallax branch. When you pull down the table there is a white background appearing at the top. This does not happen in you r parallax branch. Can you please fix that too?

steffimueller commented 9 years ago

Thank you so much for your help.

steffimueller commented 9 years ago

@ltebean Could you please help me with this last point. I guess it is just one property to set but I canot find it.

When you pull down the table there is a white background appearing at the top. This does not happen in you r parallax branch. Can you please fix that too?

steffimueller commented 9 years ago

@ltebean I still have this issue. Could you please provide a version of your parallax which does not use Storyboard or InterfaceBuilder? Please!