辅助功能:ScrollView可自动滚动到在单击“ TAB”时不可见的视图。 [英] Accessibility: ScrollView to auto scroll to the view which are not visible on hitting "TAB"

查看:142
本文介绍了辅助功能:ScrollView可自动滚动到在单击“ TAB”时不可见的视图。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人让我知道当仅键盘用户尝试使用 Tab键在ScrollView中的不同UI元素之间导航时,如何自动滚动scrollView吗?当我按 TAB键时,焦点将移至scrollView中存在的其他UI元素,但如果Visible Content View中不存在UI元素,则不会滚动。如何做到这一点。帮助将不胜感激。谢谢。

Could someone let me know how can I automatically scroll the scrollView when a keyboard-only user tries to navigate between different UI Element in the ScrollView using ‘Tab’ key? When I hit "TAB" key the focus is shifted to different UI element present in the scrollView but it doesn't scroll if the UI Element is not present in the Visible Content View. How can this be achieved. Help would be appreciated. Thanks.

推荐答案

解决方案A:创建 NSWindow 的子类并覆盖 makeFirstResponder: makeFirstResponder 在第一响应者更改时被调用。

Solution A: Create a subclass of NSWindow and override makeFirstResponder:. makeFirstResponder is called when the first responder changes.

- (BOOL)makeFirstResponder:(NSResponder *)responder {
    BOOL madeFirstResponder = [super makeFirstResponder:responder];
    if (madeFirstResponder) {
        id view = [self firstResponder];
        // check if the new first responder is a field editor
        if (view && [view isKindOfClass:[NSTextView class]] && [view isFieldEditor])
            view = [view delegate]; // the control, usually a NSTextField
        if (view && [view isKindOfClass:[NSControl class]] && [view enclosingScrollView]) {
            NSRect rect = [view bounds];
            rect = NSInsetRect(rect, -10.0, -10.0); // add a margin
            [view scrollRectToVisible:rect];
        }
    }
    return madeFirstResponder;
}

解决方案B:创建 NSTextField的子类和其他控件,并覆盖 becomeFirstResponder

Solution B: Create a subclass of NSTextField and other controls and override becomeFirstResponder.

- (BOOL)becomeFirstResponder {
    BOOL becameFirstResponder = [super becomeFirstResponder];
    if (becameFirstResponder) {
        if ([self enclosingScrollView]) {
            NSRect rect = [self bounds];
            rect = NSInsetRect(rect, -10.0, -10.0); // add a margin
            [self scrollRectToVisible:rect];
        }
    }
    return becameFirstResponder;
}

这篇关于辅助功能:ScrollView可自动滚动到在单击“ TAB”时不可见的视图。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆