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)
}
}