It seems that the keyboard doesn't have to take up the whole screen, check UPDATE in the Question section of my post. Thanks.
Use UITextField to place a full-screen keyboard on the screen.
reference
I've set up a UISplitViewController
and I would like the RootViewController
(aka MasterViewController
) to have the UITextField
with the Keyboard showing. Then I would like results of the search on the right (in the "ResultViewController" (UIViewController).
The idea is when the user types, results are proposed.
I first added a UITextField
to my RootViewController
via the storyboard
but that took up the whole screen when I activated the keyboard via textField.becomeFirstResponder()
.
I figured if I use a UIAlertController
I'd get by this issue, but the keyboard still takes up the whole screen.
class RootViewController: UIViewController {
override func viewDidLoad() {
let alertController = UIAlertController(title: "Search", message: "Search for something!.", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.placeholder = "Search"
})
self.addChildViewController(alertController)
alertController.view.frame = self.view.frame
self.view.addSubview(alertController.view)
}
}
When using a UISplitViewController
how can I get the keyboard to only stay in it's RootViewController
and not take up the whole screen?
UPDATE: It appears this has been implemented in the Netflix app on the new apple tv. The keyboard is on the top and takes up the whole width. The bottom is divided into two sections. On the left, proposed word results and on the right a collection view of video covers of possible videos. Everything is updated as the user types.
If this is considered bad design for Apple TV, then feel free to point out why.
This is what I currently get. The text box opens a keyboard that takes up the whole screen.
The best way to do this is to place your content inside a UIScrollView, then adjust the scroll view's contentInset property by the height of the keyboard when it's shown. Absolutely do not assume the keyboard height--use the value from the "keyboard will show" notification.
An object that displays an editable text area in your interface.
Presenting a keyboard only on a portion of the screen is not possible with the built-in SDK methods.
A UIKeyboard
is presented on the application's window, not on any of its subviews. To accomplish your desired behavior, use reflection to get a reference to the UIKeyboard
object on your application's UIWindow
(by iterating through the window's subviews), and change its frame to match the width of your RootViewController
.
To get started, you can look at the private UIKeyboard.h tvOS header here. I should note that Apple may have code in place to disable resizing of the keyboard (like in willMoveToWindow:
or didMoveToWindow
for example). This is undefined behavior and your milage will vary, if it even works at all.
You have deleted your comment on my answer about the Netflix app, but as shirefriendship says in their answer, Netflix probably uses a TVML template. You could go that route and build a hybrid tvOS/TVML app. Additionally, you could also manually build a keyboard yourself with a UICollectionView
in your RootViewController
.
Netflix is using TVML Templates to implement their search instead of UIKit. You can accomplish the same aesthetic as Netflix using the searchTemplate. You can learn to mix TVML and UIKit here. Unfortunately the searchTemplate is not customizable enough to conform to your desired layout. There is currently no way to implement your specific layout for the Apple TV.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With