Use of voiceover

Source: Internet
Author: User
Tags uikit

Introduction

VoiceOver is the name of Apple's "read screen" technology and is part of the accessibility feature. VoiceOver can read the information on the screen to help blind people interact with each other. This technology can be seen in Apple's various systems, OS X,ios,watchos, and even tvOS. Apple's voiceover was the first technology company in the world to receive this award from the American Foundation for the Blind, AFB, which was awarded the Helen Keller Achievement Awards on June 18, 2015. From iOS alone, the voiceover feature of iOS is no exaggeration to say that it is the best of the three mobile platforms.

While the default UI components of Apple are already supported by default for voiceover, the app usually needs to be adapted and optimized for voiceover, such as some custom complex UI components.

Basic Use

When voiceover is turned on on the iphone, you can traverse all the accessibilityelement in the current interface (UI elements that can be accessed by voiceover) by single-finger left and right swipe. When a accessibilityelement is selected, voiceover will read the accessibilityelement information. Single finger tap two times to activate the action of the current element, such as the current accessibilityelement is a button, then the corresponding button action event.

Simply put, there are a few points to note about voiceover in the app development process:

    • What are the accessibilityelement on the interface?

    • Location and shape of the accessibilityelement

    • What is the message of the accessibilityelement (that is, when the element is selected, the content is read)

    • What are the events that accessibilityelement can respond to?

The controls in Uikit are basically VoiceOver ready, and even uiview, you can actually become accessibilityelement with simple settings. So the accessibilityelement in this section are actually instances of UIView or its subclasses.

The related properties and methods are basically declared in the UIAccessibility.h header file.

So in a simple case, with UIView's Isaccessibilityelement property, you can control whether a view is accessibilityelement, in a Uikit control, like Uilabel,uibutton The Isaccessibilityelement property of these controls is true by default, and UIView this property defaults to False.

In general, the position and shape of the accessibilityelement is set by Accessibilityframe, and the default value is the position of the view on the screen, which is the rectangle shape of the view. If you want to set the value of the accessibilityframe yourself, be aware that the frame value here is relative to the device screen's coordinate system, Of course, you can use the Uiaccessibilityconvertframetoscreencoordinates function to help convert. This function has two parameters, a rect, and a view, meaning that the rect relative to the view coordinate system is converted to a value relative to the screen coordinate system and returned. So, in general, a rect can be the frame,view of the target element in the parent view as its parent view.

1 public func UIAccessibilityConvertFrameToScreenCoordinates(rect: CGRect, _ view: UIView) -> CGRect

If you want to set a non-rectangular shape, you can also customize the shape of the accessibilityelement by assigning a value of type Uibezierpath to the Accessibilitypath property.

The accessibilityelement information can be determined by the following uiaccessibility properties

    • Accessibilitylabel What is this?

    • Accessibilityhint What's the use of this, what's the result?

    • What's the value of this accessibilityvalue?

    • The type and state of the accessibilitytraits is the characterization of this element by traits, which is an enumeration type that can combine multiple attributes in a bitwise or manner.

One thing to note here is that when a view is accessibilityelement, its subviews will be masked, and this feature is sometimes useful, such as a view with multiple labels, So you want each of the following labels not to be accessible individually, then you can set this view to be accessible, and then set its accessibilitylabel to the combined value of the accessibilitylabel of all child labels.

As for the Accessibilityelement event, the simplest is that the above mentioned single finger taps two times to activate the operation of the current element, if the current accessibilityelement implements the public func Accessibilityactivate (), bool This method returns True, where this logic will be called, Otherwise, it is equivalent to a tap operation at this point in the Accessibilityelement accessibilityactivationpoint.

Advanced Applications

Accessibility Container conceived a scenario like this, a uiview that internally contains a set of content that the user can interact with, each of which is independent, but not in the form of a child view, but through Quarz 2D or core Text rendered, so this part of the content can not be turned into accessibilityelement by the way above. This situation uiview need to follow the uiaccessibilitycontainer way to describe each of the internal independent content as an instance of Uiaccessibilityelement, This time this uiview we call Accessibility Container.

The next step is to explain the specific implementation steps. First of all, how to implement after iOS 8, first accessibility container The Isaccessibilityelement value must be set to False, in addition we need to create all instances of uiaccessibilityelement , and then assign to the Accessibilityelements property (IOS 8.0+) that is assumed to be in a uiview subclass, Update the maintenance of all uiaccessibilityelement instances by means of a method called Updateaccessibleelements, when the contents of the interface change, or if the voiceover turn off state changes, Call this method to update the accessibilityelements, with the relevant pseudo-code as follows:

1 2 3 4 5 6 7 8 9 Ten One A - - the - internal func updateAccessibleElements() {   guard UIAccessibilityIsVoiceOverRunning() else {        self.accessibilityElements = nil        return   }            self.isAccessibilityElement = false   var elements = [AnyObject]()   let element1 = UIAccessibilityElement(accessibilityContainer: self)   element1.accessibilityLabel = "element1"   element1.accessibilityTraits = UIAccessibilityTraitStaticText   element1.accessibilityFrame = UIAccessibilityConvertFrameToScreenCoordinates(element1FrameInSelf, self)   elements.append(element1)        ...   self.accessibilityElements = elements}

If it is under iOS 8, then you need to implement the following several methods to achieve, more cumbersome:

1 2 3 4 5 6 // accessibilityelement number public func accessibilityelementcount ()  -> int //  Returns the Accessibilityelement public  Func accessibilityelementatindex (index: int)  -> anyobject? //  returns the index for the specified accessibilityelement Span style= "font-size:18px" >public func indexofaccessibilityelement (element:  anyobject)  -> int

Using the second method above, it is often necessary to maintain an array of all accessibilityelements, and then use the array to complete the return of the above three methods. This method is cumbersome, and when the interface update needs to refresh the content, you also need to send a notification system to tell the system interface accessibilityelements changes need to be updated. So it is more scientific to set the minimum version of the Accessibilityelements property in the case of iOS 8 or directly.

There are some doubts about the design of the Uiaccessibilityelement class, since NSObject's uiaccessibility extension already contains such things as Accessibilitylabel, Accessibilityhint These properties, why the Uiaccessibilityelement class also needs to repeatedly declare these properties, a bit of a repetition of the feeling.

Actions

Before only the simplest event, that is, single finger tap two, in fact, the common actions have the following, each action will correspond to a method, you can override the method to customize the corresponding logic of the action:

    • Activate single finger tap two times.

1 public func accessibilityActivate() -> Bool
    • Escape. Single finger z-shaped gestures are typically used to exit the modal interface or return to the previous page of navigation

1 public func accessibilityPerformEscape() -> Bool
    • Magic Tap. Two fingers tap two times to trigger most-intended action.

1 public func accessibilityPerformMagicTap() -> Bool
    • Three-finger Scroll. Three-finger sliding trigger interface horizontal or vertical scrolling

1 public func accessibilityScroll(direction: UIAccessibilityScrollDirection) -> Bool
    • Increment. Swipe up on a single point, you need to set Accessibilitytraits to uiaccessibilitytraitadjustable, otherwise the corresponding method will not be called

1 public func accessibilityIncrement()
    • Decrement. Single point slide, need to set accessibilitytraits to uiaccessibilitytraitadjustable, otherwise the corresponding method will not be called

1 public func accessibilityDecrement()

Among these methods, Escape,magic Tap,three-finger Scroll These gestures support looking up the corresponding action method in the response chain, first the user to make the corresponding gesture on the screen, The system checks that the element of the current voiceover focus is not implemented, and is not implemented, and is looked up to the upper level of the response chain. For example, some global operations, the corresponding method is written in the upper view or viewcontroller more appropriate. In fact, many of the system-provided components implement some voiceover gesture actions by default, such as Uinavigationcontroller, and Uialertcontroller provide support for escape gestures.

Accessibility Notification

Accessibility provides a series of notifications that can accomplish some specific needs. For example, you can listen for uiaccessibilityvoiceoverstatuschanged notifications to monitor the Voice over feature to turn off real-time notifications.

Or you can send some notifications in the app to make the system make some changes, such as when the accessibilityelement on your interface changes, you may send uiaccessibilitylayoutchangednotification notifications. , the notification is sent using Uiaccessibility's dedicated function, the Uiaccessibilitypostnotification function has two parameters, the first is the notification name, The second is the string you want voiceover to read, or the element that corresponds to the focus of the new voiceover.

1 UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.myFirstElement)
personal Thinking

Accessibilityelement information as concise as possible, Accessibilitylabel do not include the nature of the text, to avoid information interference

The information of each cell of the tableview is combined as much as possible, making the cell into a whole accessibilityelement, avoiding the operation of switching between meaningless redundant elements. When there are multiple buttons in the cell, consider using the magic tap, and the Magic Tap action pops the sheet style uialertcontroller for the user to manipulate.

Custom modal page note setting Accessibilityviewismodal to True, it is best to support escape gestures in the way you exit the modal page.

Set the Accessibilityelementshidden of elements that are not actually meaningful to the page to true to reduce interference during operation

Use of voiceover

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.