2

I have an element (an imageView) which shows a number. I want the voice over user to swipe up to increment and swipe down to decrement. There are a total of six numbers (images) and each number shoes different content on screen.

For that intent I made the view adjustable:

imageView.accessibilityTraits = .adjustable

I also implemented the following methods:

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

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

However, when I test this, Xcode won't go inside the increment or decrement methods.

What am I making wrong? Is there maybe a better way to increment or decrement a value using voice over?

2
  • Where have you implemented the two accessibility methods ?
    – XLE_22
    Jun 17, 2019 at 12:13
  • in the imageView's superview, where I set imageView.isAccessibilityElement = true. Jun 17, 2019 at 12:22

1 Answer 1

4

I guess you implemented the accessibilityIncrement() and accessibilityDecrement() methods in your view controller but they should belong to the created image view whose trait should be .adjustable.

Just subclass UIImageView as follows in this basic example:

class MyImageView: UIImageView {

    override var isAccessibilityElement: Bool {
        get { return true }
        set { }
    }

    override var accessibilityTraits: UIAccessibilityTraits {
        get { return .adjustable }
        set { }
    }

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

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

You just have to define what to do in each adjustable method and that should do the job.

I suggest you take a look at this site where a complete example about adjustable values with code snippets and illustrations is provided for both ObjC and Swift.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.