Upgrade to Pro — share decks privately, control downloads, hide ads and more …

macOS Catalystのメニュー対応 #hakataswift #love_swift/...

fromkk
January 25, 2020

macOS Catalystのメニュー対応 #hakataswift #love_swift/menu_for_macos_catalyst

この資料は第11回 HAKATA.swift x Swift愛好会~福岡と東京のSwift勉強会コラボ~( https://hakata-swift.connpass.com/event/149988/ )にて登壇してきたLTの資料です。

概要
WWDC 2019にてmacOS Catalystが発表され、iPadアプリをmacOSアプリ化することができるようになりました。
UIKitが利用できるのでこれまでiOSアプリを開発してきた技術がそのまま利用が可能になります。
少ない工数で配布できるプラットフォームが増えるのでビジネス的にもチャンスが広がるかと思います。
ここではiOS向けアプリケーションには無くてmacOS向けアプリケーションのUIコンポーネントにあるメニューの実装方法について紹介します。

fromkk

January 25, 2020
Tweet

More Decks by fromkk

Other Decks in Programming

Transcript

  1. 1SPpMF struct Profile { let name = "Kazuya Ueoka" let

    twitter = "@fromkk" let github = "fromkk" let qiita = "fromkk" let company = "Timers Inc." } • 2
  2. w λΠτϧόʔ  w πʔϧόʔ  w 5PVDI#BS  w

    ϝχϡʔ J04ͱNBD04ͷେ͖ͳҧ͍ 10
  3. w "QQ%FMFHBUF 6*3FTQPOEFS ʹCVJME.FOVͱ͍͏ϝιου͕ ͍ΔͷͰ࣮૷ΛՃ͑Δ w CVJMEFSTZTUFNʹDPOUFYUͷछྨ͕౉͞ΕΔͷͰϋϯυϦϯά ͢Δ ࣮૷ํ๏ #if

    targetEnvironment(macCatalyst) override func buildMenu(with builder: UIMenuBuilder) { super.buildMenu(with: builder) // TODO: build your menu } #endif IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJSFTQPOEFSCVJMENFOV 11
  4. 6*.FOV w ϝχϡʔΛߏ੒͢ΔΫϥε w λΠτϧ΍ը૾Λઃఆ͢Δ͜ͱ͕Ͱ͖Δ w DIJMESFOʹ͸6*.FOV&MFNFOUΛܧঝ͍ͯ͠ΔΫϥεΛೖΕΔ͜ͱ͕Ͱ͖ΔͷͰ࠶ؼ తʹϝχϡʔΛ࡞Δ͜ͱ͕Մೳ w ˢͷ͕ͭ6*.FOVɺ಺෦͸6*.FOV&MFNFOUͷDIJMESFO

    w BDUJPO4FMFDUPS͸࣮ߦՄೳͳ!PCKDͳϝιουΛࢦఆՄೳ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJNFOV init(title: String, image: UIImage? = nil, identifier: UIMenu.Identifier? = nil, options: UIMenu.Options = [], children: [UIMenuElement] = []) 13
  5. 6*.FOV#VJMEFS w ϝχϡʔͷߏ੒Λ؅ཧ͢ΔΫ ϥε w ϝχϡʔͷ௥Ճɺ࡟আɺೖΕ ସ͕͑Մೳ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJNFOVCVJMEFS /// Replace

    an identified menu with a menu. /// /// @param replacedIdentifier The identifier of the menu to be replaced. /// @param replacementGroup The replacement menu. func replace(menu replacedIdentifier: UIMenu.Identifier, with replacementMenu: UIMenu) /// Replace the children of an identified parent menu. /// /// @param parentIdentifier The identifier of the parent menu. /// @param childrenBlock A block that returns the new children, given the old children. func replaceChildren(ofMenu parentIdentifier: UIMenu.Identifier, from childrenBlock: ([UIMenuElement]) -> [UIMenuElement]) /// Insert a sibling menu before an identified sibling menu. /// /// @param siblingGroup The sibling menu to insert. /// @param siblingIdentifier The identifier of the sibling menu to insert before. func insertSibling(_ siblingMenu: UIMenu, beforeMenu siblingIdentifier: UIMenu.Identifier) /// Insert a sibling menu before an identified sibling menu. /// /// @param siblingGroup The sibling menu to insert. /// @param siblingIdentifier The identifier of the sibling menu to insert before. func insertSibling(_ siblingMenu: UIMenu, afterMenu siblingIdentifier: UIMenu.Identifier) /// Insert a child menu at the start of an identified parent menu. /// /// @param childGroup The child menu to insert. /// @param parentIdentifier The identifier of the parent menu to insert at the start of. func insertChild(_ childMenu: UIMenu, atStartOfMenu parentIdentifier: UIMenu.Identifier) /// Insert a child menu at the end of an identified parent menu. /// /// @param childGroup The child menu to insert. /// @param parentIdentifier The identifier of the parent menu to insert at the end of. func insertChild(_ childMenu: UIMenu, atEndOfMenu parentIdentifier: UIMenu.Identifier) /// Remove an identified menu. /// /// @param removedIdentifier The menu to remove. func remove(menu removedIdentifier: UIMenu.Identifier) 14
  6. 6*"DUJPO w Ϋϩʔδϟʔ CMPDLT Λݺͼग़ͤΔ w 6*.FOV&MFNFOUΛܧঝ͍ͯ͠ΔͷͰ6*.FOVͷDIJMESFOʹ௥ Ճ͢Δ͜ͱ͕Ͱ͖Δ 15 IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJBDUJPO

    public convenience init(title: String, image: UIImage? = nil, identifier: UIAction.Identifier? = nil, discoverabilityTitle: String? = nil, attributes: UIMenuElement.Attributes = [], state: UIMenuElement.State = .off, handler: @escaping UIActionHandler)
  7. 6*$PNNBOE w ηϨΫλʔΛݺͼग़ͤΔ w 6*.FOV&MFNFOUΛܧঝ͍ͯ͠ΔͷͰ6*.FOVͷDIJMESFOʹ௥ Ճ͢Δ͜ͱ͕Ͱ͖Δ 16 IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJDPNNBOE public convenience

    init(title: String, image: UIImage? = nil, action: Selector, propertyList: Any? = nil, alternates: [UICommandAlternate] = [], discoverabilityTitle: String? = nil, attributes: UIMenuElement.Attributes = [], state: UIMenuElement.State = .off)
  8. • αʔόʔαΠυΤϯδχΞ (PHP, Golang, AWS) • AndroidΤϯδχΞ (Kotlin) • iOSΤϯδχΞ

    (Swift) TimersͰ͸ݱࡏΤϯδχΞશ৬छ࠾༻தʂ ৄ͘͠͸”Timers”Ͱݕࡧ 23