Following the presentation from 2022 https://developer.apple.com/videos/play/wwdc2022/10002/ that show how to create a MacOs virtual machine, I was wondering if there was a way to share the clipboard between the host and the VM create?
Post
Replies
Boosts
Views
Activity
When using PKCanvasView and PKToolPicker in a SwiftUI project using Xcode 13, the PKToolPicker disappear when I blur the view, and it doesn't come back when I remove the blur effect.
I am trying to create a popup (to add some setting to the view), but here I simplify the example to just just to see the consequences of the blur effet.
When the blur effect is applied, the PKToolPicker disappear, but when I remove the effect, the PKToolPicker despot come back, so it is still possible to right non the PKCanvasView, but it is not possible to change the Pencil or the color anymore.
Does anyone know how to get the PKToolPicker back?
here is a sample code
import SwiftUI
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@State private var isBlured = false
var body: some View {
VStack {
Button(action: {
isBlured.toggle()
print("isBlured \(isBlured)")
}, label: {
Image(systemName: "questionmark")
})
DrawingView(id: nil, data: nil, title: "test").blur(radius: isBlured ? 30 : 0)
}.padding()
}
}
import SwiftUI
struct DrawingView: View {
@Environment(\.managedObjectContext) var viewContext
@State var id:UUID?
@State var data:Data?
@State var title:String?
var body: some View {
VStack{
DrawingCanvasView(data: data ?? Data(), id: id ?? UUID())
.environment(\.managedObjectContext, viewContext)
.navigationBarTitle(title ?? "Untitled",displayMode: .inline)
}
}
}
import SwiftUI
struct DrawingCanvasView: UIViewControllerRepresentable {
@Environment(\.managedObjectContext) private var viewContext
func updateUIViewController(_ uiViewController: DrawingCanvasViewController,context: Context) {
uiViewController.drawingData = data
}
typealias UIViewControllerType = DrawingCanvasViewController
var data: Data
var id: UUID
func makeUIViewController(context: Context) -> DrawingCanvasViewController {
let viewController = DrawingCanvasViewController()
viewController.drawingData = data
return viewController
}
}
import UIKit
import PencilKit
class DrawingCanvasViewController: UIViewController, PKToolPickerObserver, PKCanvasViewDelegate {
lazy var canvas: PKCanvasView = {
let view = PKCanvasView()
view.drawingPolicy = .anyInput
view.minimumZoomScale = 1
view.maximumZoomScale = 1
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
lazy var toolPicker: PKToolPicker = {
let toolPicker = PKToolPicker()
toolPicker.addObserver(self)
return toolPicker
}()
var drawingData = Data()
var drawingChanged: (Data) -> Void = {_ in}
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(canvas)
NSLayoutConstraint.activate([
canvas.leadingAnchor.constraint(equalTo: view.leadingAnchor),
canvas.trailingAnchor.constraint(equalTo: view.trailingAnchor),
canvas.topAnchor.constraint(equalTo: view.topAnchor),
canvas.bottomAnchor.constraint(equalTo: view.bottomAnchor)])
toolPicker.setVisible(true, forFirstResponder: canvas)
toolPicker.addObserver(canvas)
canvas.delegate = self
canvas.becomeFirstResponder()
if let drawing = try? PKDrawing(data: drawingData){
canvas.drawing = drawing
}
}
}