[英]Blue Highlighting / Focus Ring on Catalyst App
我目前正在使用 Project Catalyst 將我的 iOS 應用程序移植到 macOS。
我所有的文本字段、文本視圖和表格視圖在活動時都有藍色輪廓。
我在最近的測試版中在 Apple Catalyst 應用程序(例如新聞)中注意到了它,所以我希望這只是一個錯誤。
有沒有人找到其他方法將其刪除?
在 swift 你可以做
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];
希望我們能從蘋果那里得到真正的解決方案。
對 Amerino 的答案略有改進,以獲得更大的靈活性和在故事板中的使用:
@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
}
請不要這樣做 - 這是可訪問性的焦點指示器,對於僅使用鍵盤的用戶很重要。
在按下 Tab 鍵會在整個視圖周圍添加一個藍色矩形的情況下,此處提出的解決方案對我不起作用。 我已經看到它發生在 UIPageViewController 的整個頁面,UITableView 的單元格等等。 我能夠用來解決這個問題的唯一解決方案是覆蓋按鍵。
#if targetEnvironment(macCatalyst)
open override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
guard let key = presses.first?.key else { return }
switch key.keyCode {
case .keyboardTab: break
default: super.pressesBegan(presses, with: event)
}
}
#endif
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.