Skip to content

Instantly share code, notes, and snippets.

View CibelePaulinoAndrade's full-sized avatar
🎯
Focusing

Cibele Paulino Andrade CibelePaulinoAndrade

🎯
Focusing
View GitHub Profile
@CibelePaulinoAndrade
CibelePaulinoAndrade / CoreMLExample.swift
Created December 13, 2018 20:13
Core ML - Códigos utilizados na apresentação - Inteligência Computacional
var model = Flowers()
guard let prediction = try? model.prediction(data: pixelBuffer!) else {
return
}
@CibelePaulinoAndrade
CibelePaulinoAndrade / performDrop.swift
Created August 9, 2018 17:24
performDrop - Drag and Drop
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) {
@CibelePaulinoAndrade
CibelePaulinoAndrade / sessionDidUpdate.swift
Created August 9, 2018 17:21
sessionDidUpdate - Drag and Drop
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) {
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] = []
dragImageView.isUserInteractionEnabled = true
dropImageView.isUserInteractionEnabled = true
let dragImageInteraction = UIDragInteraction(delegate: self)
dragImageView.addInteraction(dragImageInteraction)
let dropImageInteraction = UIDropInteraction(delegate: self)
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 [] }
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) {
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 {
//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)
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!