0
A
回答
0
如您所知,您將NSTouchBarItem
s添加到TouchBar
實例以將項目添加到觸摸欄。
爲了添加可滾動列表,創建一個NSScrubber
的實例。一旦設置完成,您需要將NSScrubber
添加到NSCustomTouchBarItem
的自定義實例,最有可能是view
屬性。然後,您可以將該項目添加到觸摸欄。一定要閱讀鏈接的文檔。
5
NSScrollView在TouchBar上實際支持(https://developer.apple.com/reference/appkit/nstouchbar#2587738)。
NSScrubber旨在成爲項目的選取器,類似於分段控制,但具有可滾動列表的附加優點。 NSScrubber還管理它自己突出顯示的狀態,並會吃掉觸摸事件。 通過將它們彈出到滾動視圖中,您可以獲得NSButton的水平滾動列表。下面是使用約束來創建一個NSCustomTouchBarItem一個簡單的例子:
NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:CGRectMake(0, 0, 400, 30)];
NSMutableDictionary *constraintViews = [NSMutableDictionary dictionary];
NSView *documentView = [[NSView alloc] initWithFrame:NSZeroRect];
NSString *layoutFormat = @"H:|-8-";
NSSize size = NSMakeSize(8, 30);
for (int i = 0; i <= 8; i++) {
NSString *objectName = [NSString stringWithFormat:@"button%@",@(i)];
NSButton *button = [NSButton buttonWithTitle:objectName
target:nil
action:nil];
button.translatesAutoresizingMaskIntoConstraints = NO;
[documentView addSubview:button];
// Constraint information
layoutFormat = [layoutFormat stringByAppendingString:[NSString stringWithFormat:@"[%@]-8-", objectName]];
[constraintViews setObject:button forKey:objectName];
size.width += 8 + button.intrinsicContentSize.width;
}
layoutFormat = [layoutFormat stringByAppendingString:[NSString stringWithFormat:@"|"]];
NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:layoutFormat
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:constraintViews];
[documentView setFrame:NSMakeRect(0, 0, size.width, size.height)];
[NSLayoutConstraint activateConstraints:hConstraints];
scrollView.documentView = documentView;
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:@"com.TouchBar.scrollButtons"];
item.view = scrollView;
0
我剛翻譯的代碼從聖地亞哥吉爾斯威夫特4
let scrollView = NSScrollView(frame: CGRect(x: 0, y: 0, width: 400, height: 30))
var constraintViews: Dictionary<String, Any> = [:]
let documentView = NSView(frame: NSZeroRect)
var layoutFormat: String = "H:|-8-"
var size = NSSize(width: 8, height: 30)
for i in 0...8 {
let objectName: String = "button\(i)"
let button: NSButton = NSButton(title: objectName, target: nil, action: nil)
button.translatesAutoresizingMaskIntoConstraints = false
documentView.addSubview(button)
// Constraint Information
layoutFormat += "[\(objectName)]-8-"
constraintViews[objectName] = button
size.width += 8 + button.intrinsicContentSize.width
}
layoutFormat += "|"
let hConstraints: Array<NSLayoutConstraint> = NSLayoutConstraint.constraints(withVisualFormat: layoutFormat, options: .alignAllCenterY, metrics: nil, views: constraintViews)
documentView.frame = NSRect(x: 0, y: 0, width: size.width, height: size.height)
NSLayoutConstraint.activate(hConstraints)
scrollView.documentView = documentView
let item = NSCustomTouchBarItem(identifier: .controlScrubber)
item.view = scrollView
希望這可以幫助別人;-)
相關問題
- 1. Sencha帶索引欄的觸摸列表:自動滾動
- 2. 如何使用UIScrollView的滾動到頁面時,觸摸按鈕
- 3. 在滾動視圖頂部的可觸摸信息(i)按鈕
- 4. 在煎茶觸摸添加按鈕
- 5. 如何添加滾動按鈕到數據綁定,horiztonal列表
- 6. 如何在列表視圖上添加滾動按鈕?
- 7. 如何停止JqueryTools可滾動觸摸
- 8. 如何觸摸移動按鈕?
- 9. 如何觸摸Android按鈕?
- 10. Sencha觸摸工具欄,列表和按鈕在TabPanel
- 11. 可可觸摸 - 時間按鈕按下
- 12. Android觸摸和滾動列表視圖
- 13. Sencha觸摸+ PhoneGap - 列表不滾動
- 14. 如何製作可滾動(帶觸摸)影片剪輯包含按鈕 - AS3?
- 15. 如何添加觸摸事件包含滾動型
- 16. javascript滾動觸摸滾動
- 17. 可可觸摸 - 拖動按鈕觸發事件
- 18. 帶觸摸移動的拖動按鈕
- 19. 如何鏈接Sencha觸摸工具欄中的按鈕?
- 20. 如何在android應用程序的觸摸位置動態地添加按鈕?
- 21. iPhone SDK使按鈕不可觸摸/可觸摸
- 22. 如何添加添加到可可觸摸靜態庫
- 23. 添加列表煎茶觸摸屏
- 24. 包含觸摸屏使用按鈕的滾動查看器
- 25. 如何在觸摸圖像按鈕時添加動畫或縮小?
- 26. 當我觸摸TextView時觸摸按鈕
- 27. 使用Next/Previous按鈕添加滾動到水平UL列表
- 28. 可可觸摸:動畫上的觸摸
- 29. 如何提高搜索欄滾動觸摸位置
- 30. 如何防止在UINavigation欄上同時觸摸按鈕的雙重動作?