问题
I am trying to understand how does Facebook Messenger create a button at the button of the screen which stays on top of the UITableView
and follows the scrolling as well?

I want to implement the blue button on the bottom right. What should be my approach to achieve something like that?
Any push in the right direction will be highly appreciated.
回答1:
There are a few avenues to take when adding the overlay view:
As a subview of the wrapping
UINavigationController
, which means it won't scroll with the content of the tableAs a section footer of a plain-style
UITableView
that has only 1 sectionAs a subview of the
UITableView
and useUIScrollViewDelegate
'sscrollViewDidScroll:
to continuously update the view's frame as the user scroll's the table (which makes it appear to stay motionless)
回答2:
In your UIViewController subclass do this :
[self.view insertSubview:myButton aboveSubview:self.tableView];
NOTE : if your UIViewController is a UITableViewController, this code may not work, since UITableViewController place its table view as its root view, which make a lot of programmer stay away from it, because of the limitation that this imply.
回答3:
You can do this in your UITableViewController easily
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window addSubView:myButton];
I tried this and it worked for me. Good luck! :)
来源:https://stackoverflow.com/questions/16049576/create-a-button-on-top-of-uitableview