實例方法
touch
touchBarItemPresence(_:)
設置user-customized 視圖的行為。
聲明
func touchBarItemPresence(_ presence: TouchBarItemPresence) -> some View
返回值
說明此 Touch Bar 視圖行為的特征。
參數
presence
允許的
TouchBarItemPresence
說明之一。
詳述
使用touchBarItemPresence(_:)
定義用戶自定義期間特定觸控欄視圖的可見性要求。
觸控欄視圖可能是:
-
.required
: 不允許用戶刪除。 -
.default
:在用戶自定義之前默認顯示,但可移除。 -
.optional
:默認情況下不可見,但可以通過自定義調色板添加。
每個TouchBarItemPresence
都必須使用一個字符串進行初始化,該字符串是該項目的全局唯一標識符。
在下麵的示例中,除了 “Clubs” 項目之外,所有觸控欄項目默認在觸控欄中可見。它設置為.optional
,但可由用戶配置:
TextField("TouchBar Demo", text: $placeholder)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.focusable()
.touchBar {
Button("♥️", action: selectHearts)
.touchBarItemPresence(.required("heartsKey"))
Button("♣️", action: selectClubs)
.touchBarItemPresence(.optional("clubsKey"))
Button("♠️", action: selectSpades)
.touchBarItemPresence(.required("spadesKey"))
Button("♦️", action: selectDiamonds)
.touchBarItemPresence(.required("diamondsKey"))
}
可用版本
macOS 10.15+
相關用法
- Swift Optional touchBarItemPrincipal(_:)用法及代碼示例
- Swift Optional touchBar(_:)用法及代碼示例
- Swift Optional touchBar(content:)用法及代碼示例
- Swift Optional touchBarCustomizationLabel(_:)用法及代碼示例
- Swift Optional toolbar(id:content:)用法及代碼示例
- Swift Optional toolbar(content:)用法及代碼示例
- Swift Optional toggleStyle(_:)用法及代碼示例
- Swift Optional textSelection(_:)用法及代碼示例
- Swift Optional tint(_:)用法及代碼示例
- Swift Optional tabItem(_:)用法及代碼示例
- Swift Optional textContentType(_:)用法及代碼示例
- Swift Optional task(priority:_:)用法及代碼示例
- Swift Optional transaction(_:)用法及代碼示例
- Swift Optional textInputAutocapitalization(_:)用法及代碼示例
- Swift Optional truncationMode(_:)用法及代碼示例
- Swift Optional tag(_:)用法及代碼示例
- Swift Optional transformEffect(_:)用法及代碼示例
- Swift Optional task(id:priority:_:)用法及代碼示例
- Swift Optional symbolVariant(_:)用法及代碼示例
- Swift Optional popover(isPresented:attachmentAnchor:arrowEdge:content:)用法及代碼示例
- Swift Optional mask(alignment:_:)用法及代碼示例
- Swift Optional listSectionSeparatorTint(_:edges:)用法及代碼示例
- Swift Optional badge(_:)用法及代碼示例
- Swift Optional fullScreenCover(isPresented:onDismiss:content:)用法及代碼示例
- Swift Optional keyboardType(_:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Optional touchBarItemPresence(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。