I've got two controllers. On first controller I have an add button. clicking this presents the user with a second controller that contains text fields. However, the text fields aren't shown properly. It seems like they need a margin from top. As shown in this screenshot
Here is my code
First controller
class OneController < UITableViewController
....
def viewDidLoad
super
rmq.stylesheet = OneControllerStylesheet
view.tap do |table|
table.delegate = self
table.dataSource = self
rmq(table).apply_style :table
end
self.navigationItem.rightBarButtonItems = [UIBarButtonItem.alloc.initWithBarButtonSystemItem(
UIBarButtonSystemItemAdd,
target: self,
action: :addSomething)]
end
def addSomething
self.add_category_controller.player = nil
ctlr = UINavigationController.alloc.initWithRootViewController(self.add_something_controller)
ctlr.modalTransitionStyle = UIModalTransitionStyleCoverVertical
ctlr.delegate = self
self.presentViewController(ctlr, animated:true, completion:nil)
end
def add_something_controller
@add_something_controller ||= TwoController.new.tap do |ctlr|
ctlr.navigationItem.leftBarButtonItem = UIBarButtonItem.alloc.initWithBarButtonSystemItem(
UIBarButtonSystemItemCancel,
target: self,
action: :cancelAdd)
ctlr.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithBarButtonSystemItem(
UIBarButtonSystemItemDone,
target: self,
action: :doneAdd)
ctlr.navigationItem.rightBarButtonItem.enabled = false
end
end
...
end
Second controller
class TwoCategoryController < UIViewController
...
def viewDidLoad
puts "viewDidLoad"
self.view.backgroundColor = UIColor.groupTableViewBackgroundColor
self.view.addSubview(self.first_field)
self.view.addSubview(self.last_field)
end
...
end
In iOS 6 (and prior), your view would have had its origin set to {x: 0, y: 64} (in window coordinates), which is below the navigation bar.
In iOS 7, though, we now have "full screen" views almost all the time. So that's what you're bumping into here. Your view is at {x: 0, y: 0}, and so is below the navigation and status bar.
I think the correct way to fix this is to use constraints on your controller view (self.view
in TwoCategoryController
), and you can use the UIViewController#topLayoutGuide
and #bottomLayoutGuide
to position it inside the visible area.
That would be the "correct" way, but you can also make it easy on yourself and just find out the height of the nav bar (44) + status bar (20), and store that in a variable or method, and then just correct the text field frames to be offset below that.