Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

業務で絶対必要にならない技術

nakajijapan
January 27, 2017

 業務で絶対必要にならない技術

shibuya.swift #7

nakajijapan

January 27, 2017
Tweet

More Decks by nakajijapan

Other Decks in Technology

Transcript

  1. NSTouchBar • An object that provides dynamic contextual controls in

    the Touch Bar of supported models of MacBook Pro.
  2. Design • Design a contextual experience. • Use the Touch

    Bar as an extension of the keyboard and trackpad, not as a display. • Strive to match the look of the physical keyboard. • Don’t expose functionality solely in the Touch Bar. • Provide controls that produce immediate results. • Respond immediately to user interaction. • When possible, allow tasks that start in the Touch Bar to finish in the Touch Bar. • Avoid using the Touch Bar for tasks associated with well-known keyboard shortcuts. • Reflect state consistently and accurately. • Avoid mirroring Touch Bar interactions on the main screen
  3. Design • Design a contextual experience. • Use the Touch

    Bar as an extension of the keyboard and trackpad, not as a display. • Strive to match the look of the physical keyboard. • Don’t expose functionality solely in the Touch Bar. • Provide controls that produce immediate results. • Respond immediately to user interaction. • When possible, allow tasks that start in the Touch Bar to finish in the Touch Bar. • Avoid using the Touch Bar for tasks associated with well-known keyboard shortcuts. • Reflect state consistently and accurately. • Avoid mirroring Touch Bar interactions on the main screen
  4. Sample • NSTouchBar Catalog • Shows how to create bars

    and items for use in the Touch Bar • NSToolBar Sample • Shows how to add Touch Bar support to a typical Mac app
  5. Identifier fileprivate extension NSTouchBarCustomizationIdentifier { static let touchBar = NSTouchBarCustomizationIdentifier("net.nakajijapan.TouchBar")

    } fileprivate extension NSTouchBarItemIdentifier { static let play = NSTouchBarItemIdentifier(“net.nakajijapan.touchbartest001.TouchBarItem.pl ay") }
  6. NSTouchBar • Be a responder (an instance of an NSResponder

    subclass) that is present within a responder chain at runtime • Conform to the NSTouchBarProvider protocol • Implement the makeTouchBar() method within that protocol
  7. Implementation override func makeTouchBar() -> NSTouchBar? { let mainBar =

    NSTouchBar() mainBar.delegate = self mainBar.customizationIdentifier = .imageViewer mainBar.defaultItemIdentifiers = [.sharingPicker, .strokePopover, .strokeColorPicker, .photoPicker, .flexibl eSpace, .clearButton, .otherItemsProxy] mainBar.customizationAllowedItemIdentifiers = [.strokeSlider, .strokePopover, .photoPicker, .strokeColorPicker, .clearBut ton, .sharingPicker, .flexibleSpace] mainBar.principalItemIdentifier = .photoPicker return mainBar }
  8. AppDelegate if #available(OSX 10.12.2, *) { if ((NSClassFromString("NSTouchBar")) != nil)

    { NSApplication.shared() .isAutomaticCustomizeTouchBarMenuItemEnabled = true } }
  9. Button • NSCustomTouchBarItem let touchBarItem = NSCustomTouchBarItem(identifier: .showWindow1) touchBarItem.customizationLabel =

    "Window" touchBarItem.view = NSButton(title: "Window", target: self, action: #selector(showWindowItemDidTap))
  10. Group Button • NSGroupCustomTouchBarItem let touchBarItem = NSCustomTouchBarItem(identifier: .showWindow1) touchBarItem.customizationLabel

    = "Window" touchBarItem.view = NSButton(title: "Window", target: self, action: #selector(changeShowWindowBySegment)) let touchBarItem2 = NSCustomTouchBarItem(identifier: .showWindow2) touchBarItem2.customizationLabel = "Window(Top)" touchBarItem2.view = NSButton(title: "Window(Top)", target: self, action: #selector(changeShowWindowBySegment)) let group = NSGroupTouchBarItem.groupItem(withIdentifier: .showWindow, items: [touchBarItem, touchBarItem2])
  11. Popover • NSPopoverTouchBarItem let popoverItem = NSPopoverTouchBarItem(identifier: identifier) popoverItem.customizationLabel =

    "window" popoverItem.collapsedRepresentationLabel = "window" let secondaryTouchBar = NSTouchBar() secondaryTouchBar.delegate = self secondaryTouchBar.defaultItemIdentifiers = [.play]; popoverItem.pressAndHoldTouchBar = secondaryTouchBar popoverItem.popoverTouchBar = secondaryTouchBar return popoverItem
  12. Scrubber // NSScrubberDataSource func numberOfItems(for scrubber: NSScrubber) -> Int func

    scrubber(_ scrubber: NSScrubber, viewForItemAt index: Int) -> NSScrubberItemView // NSScrubberFlowLayoutDelegate func scrubber(_ scrubber: NSScrubber, layout: NSScrubberFlowLayout, sizeForItemAt itemIndex: Int) -> NSSize // NSScrubberDelegate func scrubber(_ scrubber: NSScrubber, didSelectItemAt index: Int)
  13. SharingService • NSSharingServicePickerTouchBarItem // MARK: - NSSharingServicePickerTouchBarItemDelegate extension WindowController: NSSharingServicePickerTouchBarItemDelegate

    { @available(OSX 10.12.2, *) func items(for pickerTouchBarItem: NSSharingServicePickerTouchBarItem) -> [Any] { return [NSImage(named: NSImageNameTouchBarRecordStartTemplate)!] } } let services = NSSharingServicePickerTouchBarItem(identifier: identifier) services.delegate = self
  14. override init(contentRect: NSRect, styleMask aStyle: NSWindowStyleMask, backing bufferingType: NSBackingStoreType, defer

    flag: Bool) { super.init(contentRect: contentRect, styleMask: aStyle, backing: bufferingType, defer: flag) isReleasedWhenClosed = true displaysWhenScreenProfileChanges = true backgroundColor = NSColor.clear isOpaque = false hasShadow = false collectionBehavior = [.fullScreenPrimary] isMovable = true isMovableByWindowBackground = true styleMask = [NSBorderlessWindowMask, NSResizableWindowMask] ignoresMouseEvents = false level = Int(CGWindowLevelForKey(.floatingWindow)) NotificationCenter.default.addObserver(self, selector: #selector(recordButtonDidClick(_:)), name: NSNotification.Name(rawValue: "CaptureViewRecordButtonDidClick"), object: nil) setFrame(NSRect(x: 200, y: 200, width: 500, height: 500), display: true) NSEvent.addLocalMonitorForEvents(matching: .keyDown) { (aEvent) -> NSEvent? in self.keyDown(with: aEvent) return aEvent } }
  15. override init(contentRect: NSRect, styleMask aStyle: NSWindowStyleMask, backing bufferingType: NSBackingStoreType, defer

    flag: Bool) { super.init(contentRect: contentRect, styleMask: aStyle, backing: bufferingType, defer: flag) isReleasedWhenClosed = true displaysWhenScreenProfileChanges = true backgroundColor = NSColor.clear isOpaque = false hasShadow = false collectionBehavior = [.fullScreenPrimary] isMovable = true isMovableByWindowBackground = true styleMask = [NSBorderlessWindowMask, NSResizableWindowMask] ignoresMouseEvents = false level = Int(CGWindowLevelForKey(.floatingWindow)) NotificationCenter.default.addObserver(self, selector: #selector(recordButtonDidClick(_:)), name: NSNotification.Name(rawValue: "CaptureViewRecordButtonDidClick"), object: nil) setFrame(NSRect(x: 200, y: 200, width: 500, height: 500), display: true) NSEvent.addLocalMonitorForEvents(matching: .keyDown) { (aEvent) -> NSEvent? in self.keyDown(with: aEvent) return aEvent } } ݪҼ͸෼͔Βͣɻɻɻ