Reputation: 415
I’ve overridden the accessibilityPerformMagicTap() function in a UIViewController subclass to detect the magic tap gesture for that view controller. However, when triggering the magic tap, the function is not being called.
How can I properly observe the magic tap gesture?
I also tried adding this function in AppDelegate, but it didn’t receive a callback either.
Note: I haven’t used the accessibilityPerformMagicTap() function anywhere else in my project.
Below i have attached the sample code.
class SecondaryVC : UIViewController{
private var actionButton : UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = .systemGreen
button.setTitle("Add", for: .normal)
button.layer.cornerRadius = 8
return button
}()
override func viewDidLoad(){
super.viewDidLoad()
view.backgroundColor = .systemTeal
//Suggestion from StackOverFlow (Can't access subviews)
view.isAccessibilityElement = true
view.accessibilityTraits = [.button]
view.accessibilityLabel = "Secondary View focused"
tabBarItem = UITabBarItem(title: "Secondary", image: UIImage(systemName: "square"), selectedImage: UIImage(systemName: "square.fill"))
addSubViews()
}
override class func accessibilityPerformMagicTap() -> Bool {
print(">>>> SecondaryVC accessibilityPerformMagicTap")
return true
}
override class func accessibilityPerformEscape() -> Bool {
print(">>>> secodaryVC EscapeAction")
return true
}
private func addSubViews(){
view.addSubview(actionButton)
actionButton.translatesAutoresizingMaskIntoConstraints = false
actionButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor,constant: 16).isActive = true
actionButton.leadingAnchor.constraint(equalTo: view.leadingAnchor,constant: 16).isActive = true
actionButton.trailingAnchor.constraint(equalTo: view.trailingAnchor,constant: -16).isActive = true
}
}
Upvotes: 0
Views: 8