2015-10-10 42 views
2

我已經使用UISearchController和表視圖實現了一個搜索屏幕。當我開始搜索某些內容時,搜索控制器會在表視圖頂部添加一個視圖(儘管它什麼都不做),並且在我設置searchController.active = false之前,VoiceOver無法訪問表視圖。我已經嘗試了幾乎所有的東西,唯一的解決方案是放棄UISearchController for UISearchBar。目前,一旦顯示鍵盤並且搜索控制器處於活動狀態,VoiceOver選擇器將從文本字段轉到條形按鈕項目,然後跳過表格視圖並轉到鍵盤。這是我的UISearchController的設置。UISearchController無法訪問

searchController = UISearchController(searchResultsController: nil) 
    searchController.searchResultsUpdater = self 
    searchController.delegate = self 
    searchController.hidesNavigationBarDuringPresentation = false 
    searchController.dimsBackgroundDuringPresentation = false 
    searchController.searchBar.searchBarStyle = .Minimal 
    searchController.searchBar.keyboardAppearance = .Dark 
    searchController.searchBar.showsCancelButton = false 
    searchController.searchBar.delegate = self 
    searchController.searchBar.text = prefilledSearch 
    searchController.view.layer.borderColor = UIColor.redColor().CGColor 
    searchController.view.layer.borderWidth = 1.0 
    searchController.view.isAccessibilityElement = false 
    searchController.view.hidden = true 
    searchController.searchBar.setShowsCancelButton(false, animated: false) 

我該如何解決這個問題並繼續使用UISearchController?目前,搜索功能無法在我的應用中與VoiceOver用戶使用。

回答

2

這是因爲底層UITransitionViewaccessibilityViewIsModalSelector設置了不正確的值,它在搜索視圖中捕獲VO,在您的情況下爲空。

我只能想到在私人UITransitionView上用swizzling accessibilityViewIsModal修補此行爲。

我所描述的技術在博客我寫: http://www.morphineapps.com/blog/accessibility-on-ios

相關學家:

https://gist.github.com/pronebird/0d3c06485de50e100d1e93bcde08c94c#file-snippet-m https://gist.github.com/pronebird/66aa70b005ed9af8d357cdc7e940542b#file-search-controller-snippet-m

+0

在斯威夫特,你可以做 'FUNC didPresentSearchController(_ searchController:UISearchController){? searchController.view.superview .accessibilityViewIsModal =假 }' – Maximilian

+0

@Maximilian這沒」 t在發佈這個答案時爲我工作。 – Andy

0

從我在這個頁面上發現的http://www.iaccessibility.net/report/uisearching-for-accessibility-nil,問題是你設置searchResultsController爲零,這使得原始視圖控制器顯示搜索結果。當搜索控制器具有焦點時,會阻止VoiceOver訪問原始視圖控制器中的搜索結果。通過指定一個單獨的結果視圖控制器,VoiceOver將起作用。

0

我發現,接受的答案是不理想的,即使它可能在技​​術上是正確的。

如果您使用obscuresBackgroundDuringPresentation(在iOS 9.1中添加)並將其設置爲false,則VoiceOver可以訪問基礎表視圖。

用法:

searchController.obscuresBackgroundDuringPresentation = false