Show common user interface elements from Apple TV in your native app using TVUIKit.

TVUIKit Documentation

Posts under TVUIKit tag

10 Posts
Sort by:
Post not yet marked as solved
0 Replies
240 Views
how do I put the app i am developing on my apple th for testing?my apple tv is the latest 4K model.
Posted Last updated
.
Post not yet marked as solved
1 Replies
221 Views
I'm working on TVOS with new Remote and wanted to change the behavior of UIPress.PressType.leftArrow but couldn't found a solution so far. Here is my testing code to disable the buttons, but the buttons are still working Please, advise me to solve the problem class MyScrollView: UIScrollView {  override var canBecomeFocused: Bool { true }  override init(frame: CGRect) {   super.init(frame: frame)  }  required init?(coder: NSCoder) {   fatalError("init(coder:) has not been implemented")  }  override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {   print("\(type(of: self))::\(#function)")  }  override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) {   print("\(type(of: self))::\(#function)")  }  override func pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?) {   print("\(type(of: self))::\(#function)")  } } class ContainerView: UIView {  override init(frame: CGRect) {   super.init(frame: frame)  }  required init?(coder: NSCoder) {   fatalError("init(coder:) has not been implemented")  }  override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {   print("\(type(of: self))::\(#function)")  }  override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) {   print("\(type(of: self))::\(#function)")  }  override func pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?) {   print("\(type(of: self))::\(#function)")  } } class ViewController: UIViewController {  let scrollView = MyScrollView()  let contentView = ContainerView()  override func viewDidLoad() {   super.viewDidLoad() //  // Do any additional setup after loading the view.   scrollView.translatesAutoresizingMaskIntoConstraints = false   contentView.translatesAutoresizingMaskIntoConstraints = false   view.addSubview(scrollView)   NSLayoutConstraint.activate([    scrollView.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 5),    scrollView.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 5),    scrollView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),    scrollView.heightAnchor.constraint(equalToConstant: 100)   ])   scrollView.addSubview(contentView)   NSLayoutConstraint.activate([    contentView.topAnchor.constraint(equalTo: scrollView.topAnchor),    contentView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),    contentView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),    contentView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),    contentView.heightAnchor.constraint(equalTo: scrollView.heightAnchor),    contentView.widthAnchor.constraint(equalToConstant: 6400)   ])   contentView.backgroundColor = UIColor.red.withAlphaComponent(0.5)   scrollView.panGestureRecognizer.allowedTouchTypes = [    NSNumber(value: UITouch.TouchType.indirect.rawValue)   ]   scrollView.panGestureRecognizer.allowedPressTypes = []  }  override func viewDidLayoutSubviews() {   super.viewDidLayoutSubviews()   scrollView.contentInset = UIEdgeInsets(top: 0,                       left: scrollView.bounds.width / 2,                       bottom: 0,                       right: scrollView.bounds.width / 2)  } }
Posted Last updated
.
Post not yet marked as solved
1 Replies
233 Views
I am attempting to detect changes of a UISlider value using the observer option but I am not getting any output. Selected parts of code here class MainViewController: UIViewController {     @IBOutlet weak var speedSlider: UISlider!     var speedSliderObserver:  NSKeyValueObservation?     override func viewDidLoad() {   super.viewDidLoad()         setSettings()     }     func setSettings() {         speedSliderObserver = speedSlider.observe(.value, options: [.old, .new]) { object, change in             print("speedSlider from: (change.oldValue!), to: (change.newValue!)")         } } Am I using observe correctly or is there some other way?
Posted Last updated
.
Post not yet marked as solved
0 Replies
223 Views
Based on documentation, I would assume item scanning in Accessibility mode's Switch Control utilizes the underlying API - Focus-based Navigation from UI Kit (please correct me if I'm wrong). Where is the documentation for the other type of scanning it shows in the above link, point scanning? Thanks.
Posted
by dlew00.
Last updated
.
Post marked as solved
2 Replies
344 Views
I would like to click an element without user input. I see it's possible in XCUIElement which is a part of the XCTest framework to ensure things are working correctly, and I'm aware of various other testing frameworks that support E2E testing with simulated clicks. But is it possible to trigger this in production outside of testing? E.g. How app remotes work for a TV - pressing a button on the app will move right, left, or click an object on the TV (only remove the TV from this question and have it target the OS it's running on)
Posted
by dlew00.
Last updated
.
Post marked as solved
2 Replies
887 Views
I have in my project different code which is responsible for the blur effect in my app. In tvOS 13 this worked fine but in tvOS 14 I have to remove the code otherwise the app will crash. What exactly do I have to change in the code to make it run on tvOS 14. Thanks for the help. private func sharedSetup(effect: UIBlurEffect, radius: CGFloat = 90) {&#9;&#9;&#9; let UICustomBlurEffect = NSClassFromString("_UICustomBlurEffect") as! UIBlurEffect.Type let raw = effect.value(forKey: "_style") as! Int let style = UIBlurEffect.Style(rawValue: raw)! let effect = UICustomBlurEffect.init(style: style)&#9;&#9;&#9;&#9;&#9;&#9; effect.setValue(1.0, forKey: "scale")&#9;&#9; effect.setValue(radius, forKey: "blurRadius")&#9;&#9;&#9; effect.setValue(UIColor.clear, forKey: "colorTint") self.blurEffect = effect&#9; }
Posted
by janapple.
Last updated
.
Post marked as solved
1 Replies
411 Views
On tvOS you can choose Settings > Accessibility > Display > Focus Style > High Contrast to have teasers highlighted by a white border when focused: However, I cannot find out how to use this feature on my own custom views. It seems that only TVPosterView makes use of this High Contrast accessibility setting. I'd like to be able to show such a frame on my custom views if this setting is enabled but I cannot find how to check if it's enabled. None of the bools listed on https://developer.apple.com/documentation/uikit/uiaccessibility under Capabilities (like isVoiceOverRunning, isGuidedAccessEnabled, isReduceTransparencyEnabled, etc.) seems to refer to this Focus Style setting. Can anybody point me in the right direction? How do I check in code whether Focus Style is set to High Contrast? How do I get the High Contrast frame on non-TVPosterView views?
Posted
by Eurydice.
Last updated
.
Post marked as solved
3 Replies
596 Views
What follows is about tvOS 15 but may also apply to iOS 15. Our app may display several types of UICollectionView cells and it depends on the content sent by our backend. Prior to tvOS 15, we used to lazily instantiate UICollectionView cell registrations when needed for the first time while building a UICollectionViewDiffableDataSource. Eventually, each cell registration is only instantiated once (or never). Now tvOS 15 throws an exception when doing so, pretending to prevent the app from creating a new cell registration each time. And it does not care whether it's actually a new cell registration each time or one that is lazily instantiated once. Here is the exception: *** Assertion failure in -[UICollectionView dequeueConfiguredReusableCellWithRegistration:forIndexPath:item:], UICollectionView.m:7413 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to dequeue a cell using a registration that was created inside -collectionView:cellForItemAtIndexPath: or inside a UICollectionViewDiffableDataSource cell provider. Creating a new registration each time a cell is requested will prevent reuse and cause created cells to remain inaccessible in memory for the lifetime of the collection view. Registrations should be created up front and reused. Registration: <UICollectionViewCellRegistration: 0x6000000f8c60>' I understand the concern but lazy instantiation is a thing and it should not be for forbidden for the sake of best practices that are not related to it. In my humble opinion, this assert should be removed and apps should be allowed to create cell registrations on the fly.
Posted
by patatrouf.
Last updated
.
Post not yet marked as solved
3 Replies
835 Views
Hi, I'm having an issue with TVCollectionViewFullScreenLayout. The requirement is that a user can pick from a collection view of items which then presents a new ViewController with a UICollectionView using TVCollectionViewFullScreenLayout populated with cells derived from TVCollectionViewFullScreenCell, with the initial position set to the same item the user selected. Calling collectionView.scrollToItemAt initially works but then it snaps back one position to the previous cell. Simply adding one to the index position leaves the user with an ugly animation as the view loads and then scrolls to the correct position. I investigated the .centerIndexPath property but this is get only. An example of the correct behaviour can be found in the TV app when selecting a title from a horizontal list of suggestions. The view that is presented starts with the item the user selected.
Posted Last updated
.