0
我有一個帶有按鈕和帶有標題框的NSView的工具欄。當窗口打開並且Voice Over打開時,我希望焦點位於標題框中。目前它位於工具欄按鈕上,因爲它在可訪問性層次結構中可能更高。我該怎麼做才能專注於框,而不是按鈕?以可編程方式專注於可可的UI元素
由於
我有一個帶有按鈕和帶有標題框的NSView的工具欄。當窗口打開並且Voice Over打開時,我希望焦點位於標題框中。目前它位於工具欄按鈕上,因爲它在可訪問性層次結構中可能更高。我該怎麼做才能專注於框,而不是按鈕?以可編程方式專注於可可的UI元素
由於
的解決方案是訪問該窗口可訪問性層次結構在windowDidLoad
這樣的:
id windowElement = NSAccessibilityUnignoredDescendant(self.window);
NSArray *windowElements = [windowElement accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
其被認爲是在第一層級中的元件應該在windowElements
陣列中找到後。假設我們發現它和它的指數是firstElIndex
則:
NSMutableArray *mutArray = [NSMutableArray arrayWithArray:windowElements];
id firstElement = [[mutArray objectAtIndex:firstElIndex] retain];
[mutArray removeObject:firstElement];
[mutArray insertObject:firstElement atIndex:0];
[windowElement accessibilitySetOverrideValue:mutArray forAttribute:NSAccessibilityChildrenAttribute];
[windowElement accessibilitySetOverrideValue:mutArray forAttribute:NSAccessibilityVisibleChildrenAttribute];
[windowElement accessibilitySetOverrideValue:mutArray forAttribute:NSAccessibilitySelectedChildrenAttribute];
[firstElement release];
最後我們覆蓋windowElement
孩子用新的數組,其中元素,我們希望將焦點放在將是擺在首位的屬性。
這是一個非常簡單的例子。但這是要走的路。