12

我目前正在使用 Project Catalyst 将我的 iOS 应用程序移植到 macOS。

我所有的文本字段、文本视图和表格视图在活动时都有蓝色轮廓。

我在最近的测试版中注意到它在 Apple Catalyst 应用程序(例如新闻)中,所以我希望它只是一个错误。

有没有人找到其他方法来删除它?

4

6 回答 6

20

迅速你可以做


extension UITextView {
    #if targetEnvironment(macCatalyst)
    @objc(_focusRingType)
    var focusRingType: UInt {
        return 1 //NSFocusRingTypeNone
    }
    #endif
}

于 2019-10-11T17:29:07.063 回答
11

它有助于在 Catalyst 的所有“视图”类中禁用对焦环

extension UIView {
    #if targetEnvironment(macCatalyst)
    @objc(_focusRingType)
    var focusRingType: UInt {
        return 1 //NSFocusRingTypeNone
    }
    #endif
}
于 2020-05-15T10:05:32.827 回答
2

请不要这样做 - 这是可访问性的焦点指示器,对于仅使用键盘的用户很重要。

于 2020-12-19T23:13:47.343 回答
1

有一个_setFocusRingType:似乎与NSView API匹配的私有方法。我可以用它来消除对焦环,尽管这可能无法通过应用程序审查。

使用此功能需您自担风险:

SEL selector = NSSelectorFromString(@"_setFocusRingType:");
NSMethodSignature *signature = [self.textView methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
NSUInteger arg = 1; // NSFocusRingTypeNone
[invocation setArgument:&arg atIndex:2];
[invocation invokeWithTarget:self.textView];

希望我们能从 Apple 那里得到真正的解决方案。

于 2019-09-06T20:53:40.420 回答
1

对 Amerino 的答案稍作改进,以提高灵活性并在 Storyboard 中使用:

@IBDesignable
class UITextViewCS: UITextView {
    @IBInspectable
    public var focusRing: UInt = 1 // 0-default, 1-None, 2-Exterior

    #if targetEnvironment(macCatalyst)
    @objc(_focusRingType)
    var focusRingType: UInt {
        guard [0, 1, 2].contains(focusRing) else { return 0 }
        return focusRing
    }
    #endif
}
于 2020-04-16T17:34:36.063 回答
1

如果符合您的需要,这也可以在 Interface Builder 中针对特定按钮不使用任何代码来完成。

在身份检查器中,只需将用户定义的运行时属性设置为 1,如下所示:

在此处输入图像描述

于 2020-07-23T10:13:22.330 回答