Accessibility accessibilityDecrement() not getting

2019-08-08 12:52发布

Why are not accessibilityDecrement() and accessibilityIncrement() getting called in my custom UITextView when performing the appropriate gestures?

class CustomTextView: UITextView  {

   required init?(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
      accessibilityTraits = accessibilityTraits | UIAccessibilityTraitAdjustable
   }

   override func accessibilityDecrement() {
      print("Decrement")
   }

   override func accessibilityIncrement() {
      print("Increment")
   }
}

2条回答
我命由我不由天
2楼-- · 2019-08-08 13:43

Try with:

isAccessibilityElement = true

accessibilityTraits = super.accessibilityTraits | UIAccessibilityTraitAdjustable
查看更多
狗以群分
3楼-- · 2019-08-08 13:43

My bad. Turns out I had forgotten that I was setting textView.accessibilityTraits = UIAccessibilityTraitStaticText in the ViewController.viewDidLoad. Duhh...

查看更多
登录 后发表回答