我目前正在使用 Project Catalyst 将我的 iOS 应用程序移植到 macOS。
我所有的文本字段、文本视图和表格视图在活动时都有蓝色轮廓。
我在最近的测试版中注意到它在 Apple Catalyst 应用程序(例如新闻)中,所以我希望它只是一个错误。
有没有人找到其他方法来删除它?
我目前正在使用 Project Catalyst 将我的 iOS 应用程序移植到 macOS。
我所有的文本字段、文本视图和表格视图在活动时都有蓝色轮廓。
我在最近的测试版中注意到它在 Apple Catalyst 应用程序(例如新闻)中,所以我希望它只是一个错误。
有没有人找到其他方法来删除它?
迅速你可以做
extension UITextView {
#if targetEnvironment(macCatalyst)
@objc(_focusRingType)
var focusRingType: UInt {
return 1 //NSFocusRingTypeNone
}
#endif
}
它有助于在 Catalyst 的所有“视图”类中禁用对焦环
extension UIView {
#if targetEnvironment(macCatalyst)
@objc(_focusRingType)
var focusRingType: UInt {
return 1 //NSFocusRingTypeNone
}
#endif
}
请不要这样做 - 这是可访问性的焦点指示器,对于仅使用键盘的用户很重要。
有一个_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 那里得到真正的解决方案。
对 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
}