简体   繁体   中英

UISearchBar iOS 13 voice dictation button

iOS 13 has voice dictation button in UISearchBar in all system applications, which duplicates mic button on system keyboard and shows dictation view:
在此处输入图像描述
But when I create new project in Xcode, add UISearchBar, and run application on device, it doesn't have mic button on UISearchBar.
Is there a way to make my application show that mic button on UISearchBar?

You can set the search bar book mark item to be visible and then change the image to be an image of the microphone. Then you can programmatically use the search bar delegate method "searchBarBookmarkButtonClicked" to set your action for clicking on the button. This will trigger UISpeech to listen and analyze the voice. Make sure you have the correct info.plist properties "Privacy - Microphone Usage Description" and "Privacy - Speech Recognition Usage Description" set to ask the user for permission.

There is a UISearchTextField instance in the UISearchBar. You can set the textField.rightView to a view of microphone. In the microphone button handler, you do the the speech-to-text recognition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM