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

# Type にDrag and Dropの実装をしてみた/type_with_drag_and_drop

fromkk
June 21, 2017

# Type にDrag and Dropの実装をしてみた/type_with_drag_and_drop

# Type にDrag and Dropの実装をしてみた

fromkk

June 21, 2017
Tweet

More Decks by fromkk

Other Decks in Programming

Transcript

  1. ܰ͘ৼΓฦΓ • iMac Pro/iPad Pro 10.5Πϯν/HomePod౳ͷ৽঎඼ • iMac/Macbook ProͷΞοϓάϨʔυ •

    CoreML/Vision/ARKit/VRKit౳ͷ৽ٕज़ • CoreNFC/Music Kit౳৽APIͷղ์ • iOS 11/tvOS 11/watchOS 4/macOS High Sierra • etc... 4
  2. Drag and Dropؔ࿈ηογϣϯ • 203 Introducing Drag and Drop •

    223 Drag and Drop with Collection and Table View • 227 Data Delivery with Drag and Drop 5
  3. ԿނDrag and DropରԠͳͷ͔ • ❌ iMac Pro͸ख͕ग़ͤͳ͍ • ❌ HomePod͸དྷ೥Ҏ߱ʹͳΒͳ͍ͱ೔ຊͰൃച͠ͳ͍

    • ⭕ iPad Pro͸લ͔Βཉ͔ͬͨ͠ • ⭕ αΠζมΘΒͣϕθϧ͕ࡉ͘ͳΔ͚ͩͱ͔࠷ߴ↗ • ⭕ ৽͍͠࢓૊Έͩ͠ࢼͯ͠Έ͍ͨ‼ 6
  4. Dragͷ࣮૷ํ๏ʢͦͷ1ʣ func addSupportDragInteractionIfNeeded() { if #available(iOS 11.0, *) { let

    dragInteraction = UIDragInteraction(delegate: self) self.addInteraction(dragInteraction) } } 13
  5. Dragͷ࣮૷ํ๏ʢͦͷ2ʣ @available (iOS 11.0, *) extension IndexViewCell: UIDragInteractionDelegate { func

    dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] { let provider = NSItemProvider(object: self.article.markdown as NSString) let dragItem = UIDragItem(itemProvider: provider) return [dragItem] } } 14
  6. Dropͷ࣮૷ํ๏(ͦͷ1) func addSupportDropInteractionIfNeeded() { if #available(iOS 11.0, *) { let

    dropInteraction = UIDropInteraction(delegate: self) self.view.addInteraction(dropInteraction) } } 17
  7. Dropͷ࣮૷ํ๏(ͦͷ2) @available(iOS 11.0, *) extension RegisterViewController: UIDropInteractionDelegate { func dropInteraction(_

    interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool { return session.canLoadObjects(ofClasses: [UIImage.self]) } func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal { return UIDropProposal(operation: .copy) } func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) { session.loadObjects(ofClass: UIImage.self) { (items) in items.forEach({ (item) in guard let image: UIImage = item as? UIImage else { return } self.upload(image) }) } } } 18