This file contains 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 SwiftUI | |
import PlaygroundSupport | |
struct MyView: View { | |
@State var viewOffset: CGSize = .zero { | |
didSet { | |
let newFrame = viewFrame.offsetBy(dx: self.viewOffset.width, dy: self.viewOffset.height) | |
self.canDrop = containerFrame.intersects(newFrame) |
This file contains 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
struct DraggablePita: View { | |
var body: some View { | |
Image(uiImage: UIImage(named: "pita.png")!) | |
.draggable() // Add the new, custom modifier to make this draggable | |
} | |
} | |
// Handle dragging | |
struct DraggableView: ViewModifier { | |
@State var offset = CGPoint(x: 0, y: 0) |
This file contains 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
/** | |
_____ _____ _ | |
| __ \ / ____| | | | |
| | | | ___| | _ __ _ _ _ __ | |_ ___ _ __ | |
| | | |/ _ \ | | '__| | | | '_ \| __/ _ \| '__| | |
| |__| | __/ |____| | | |_| | |_) | || (_) | | | |
|_____/ \___|\_____|_| \__, | .__/ \__\___/|_| | |
__/ | | | |
|___/|_| | |
*/ |