Open keyboard without clicking on TextField on tvOS - Swift
While your UI is questionable, once your first text field finishes editing, you could start the other one.
Set the first text field UITextFieldDelegate to the view controller, and then:
class ViewController: UIViewController , UITextFieldDelegate{
@IBOutlet weak var tf2: UITextField!
@IBOutlet weak var tf1: UITextField!
@IBAction func click() {
tf1.becomeFirstResponder()
}
func textFieldDidEndEditing(_ textField: UITextField) {
if (textField == tf1){
tf2.becomeFirstResponder()
}
}
}
I want to use it as a UIButton when I tap UITextField
1) Make the view controller implement this delegate: UITextFieldDelegate
class YourViewController: UIViewController, UITextFieldDelegate {
// ...
yourTextField.delegate = self
// ...
}
2) Return false in textFieldShouldBeginEditing
, so the text field doesn't respond and the keyboard doesn't open. Instead, open yours or do whatever you want.
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
// HERE, open your keyboard or do whatever you want
return false
}
Side keyboard on tvOs
The keyboard appears on the side like this if the system detects that the Siri Remote isn't paired. For example, if you normally use a universal remote to control your Apple TV, this keyboard would be easier to use with only the arrow keys.
If you pair a Siri Remote, then the keyboard will use its normal "linear" appearance.
tvOS keyboard language
On your apple TV go to Settings -> General -> Language, switch to the language you need (Russian). It will ask you if you're OK with Siri not being supported, hit OK, and voila :
this doesn't work in simulator unfortunately.
Also, you might try to create a custom keyboard, and make it's primaryLanguage whatever you need:
https://developer.apple.com/library/tvos/documentation/UIKit/Reference/UIInputViewController_Class/index.html#//apple_ref/doc/uid/TP40014279-CH1-DontLinkElementID_8
tvOS SearchController, avoid collapsing keyboard
It was not really possible until tvOS 14, when Apple released new property searchControllerObservedScrollView
: https://developer.apple.com/documentation/uikit/uisearchcontroller/3584820-searchcontrollerobservedscrollvi
By setting your collectionView on this property, the SearchController will automatically adapt searchbar + keyboard position to your CollectionView offset.
You can adapt your code this way :
private lazy var searchController: UISearchController = {
let searchController = UISearchController(searchResultsController: searchResultsController)
if #available(tvOS 14.0, *) {
searchController.searchControllerObservedScrollView = (searchResultsController as? UICollectionViewController)?.collectionView
}
return searchController
}()
To get rid of nullable cast, just change searchResultsController
return type to UICollectionViewController
. It should not affect your implementation.
Related Topics
Swift Sprite Kit in App Purchase
Mandatory Init Override in Swift Uinavigationcontroller Subclass
Swift: Differencebetween a Typealias and an Associatedtype with a Value in a Protocol
Generic Method Override Not Working in Swift
Non-Modular Headers of Openssl Library When Using Modulemap for Swift Framework
Classes in Swift Files Inside Folder References Not Seen by Xcode 10's Compiler
Passing Dynamic Int Variable from One Class to Another Class in Swift
How to Set iOS 13 Glyphs Programmatically
Spritekit Skphysicsjointfixed Odd Behaviour
Best Way to Structure My Firebase Database
Swift Build' on Terminal Throw 'Error: Root Manifest Not Found'
Avoid Automatic Framework Linking in Swift
Behaviour of Protocols with Self
Fullscreen for Swift Playgrounds on iPad