This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var model = Flowers() | |
guard let prediction = try? model.prediction(data: pixelBuffer!) else { | |
return | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) { | |
if session.canLoadObjects(ofClass: String.self) { | |
session.loadObjects(ofClass: String.self) { (items) in | |
let values = items as [String] | |
self.dropTextView.text = values.last | |
} | |
} else if session.canLoadObjects(ofClass: UIImage.self) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal { | |
let location = session.location(in: self.view) | |
let dropOperation: UIDropOperation? | |
if session.canLoadObjects(ofClass: String.self) { | |
if dropTextView.frame.contains(location) { | |
dropOperation = .copy | |
} else if dropImageView.frame.contains(location) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController: UITextDragDelegate { | |
func textDraggableView(_ textDraggableView: UIView & UITextDraggable, dragPreviewForLiftingItem item: UIDragItem, session: UIDragSession) -> UITargetedDragPreview? { | |
let dragView = textDraggableView | |
let selectionRange = textDraggableView.selectedTextRange | |
let selectionRects = textDraggableView.selectionRects(for: selectionRange!) as! [UITextSelectionRect] | |
var array: [CGRect] = [] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dragImageView.isUserInteractionEnabled = true | |
dropImageView.isUserInteractionEnabled = true | |
let dragImageInteraction = UIDragInteraction(delegate: self) | |
dragImageView.addInteraction(dragImageInteraction) | |
let dropImageInteraction = UIDropInteraction(delegate: self) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func dragInteraction(_ interaction: UIDragInteraction, itemsForAddingTo session: UIDragSession, withTouchAt point: CGPoint) -> [UIDragItem] { | |
// Adicionar novos itens a seleção | |
if let textView = interaction.view as? UITextView { | |
let textToDrag = textView.text | |
let provider = NSItemProvider(object: textToDrag! as NSString) | |
let item = UIDragItem(itemProvider: provider) | |
return [item] | |
} | |
else if let imageView = interaction.view as? UIImageView { | |
guard let image = imageView.image else { return [] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController: UIDropInteractionDelegate { | |
func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal { | |
let location = session.location(in: self.view) | |
let dropOperation: UIDropOperation? | |
if session.canLoadObjects(ofClass: String.self) { | |
if dropTextView.frame.contains(location) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController: UIDragInteractionDelegate { | |
//Método usado para pegar um item | |
func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] { | |
if let textView = interaction.view as? UITextView { | |
let textToDrag = textView.text | |
let provider = NSItemProvider(object: textToDrag! as NSString) | |
let item = UIDragItem(itemProvider: provider) | |
return [item] | |
} | |
else if let imageView = interaction.view as? UIImageView { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Habilitando interações | |
dragImageView.isUserInteractionEnabled = true | |
dropImageView.isUserInteractionEnabled = true | |
dragTextView.isUserInteractionEnabled = true | |
dropTextView.isUserInteractionEnabled = true | |
//Adicionando interações de Drag | |
let dragImageInteraction = UIDragInteraction(delegate: self) | |
let dragTextInteraction = UIDragInteraction(delegate: self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var dragTextView: UITextView! | |
@IBOutlet weak var dropTextView: UITextView! | |
@IBOutlet weak var dragImageView: UIImageView! | |
@IBOutlet weak var dropImageView: UIImageView! | |
NewerOlder