我想要一张可以用来画画的 Canvas 。目标将是一个基于 iOS 的 Swift playground。我搜索了文档,但找不到名为 Canvas 的对象,但如果有类似的东西,那对我也有好处。
最佳答案
您可以使用与此类似的东西,注意您不必使用 Sprite Kit 类。
import UIKit
import PlaygroundSupport
import SpriteKit
// Playground Container Setup
//
//
let containerWidth: CGFloat = 667.0
let containerHeight: CGFloat = 375.0
let containerCenter: CGPoint = CGPoint(x: (containerWidth/2), y: (containerHeight/2))
let containerView = SKView(frame: CGRect(x: 0.0, y: 0.0, width: containerWidth, height: containerHeight))
PlaygroundPage.current.liveView = containerView
let containterScene: SKScene = SKScene(size: CGSize(width: containerWidth, height: containerHeight))
containerView.presentScene(containterScene)
已更新
我创建了一个包装器类,让每个人都能更轻松地完成这项工作。在 github 上下载 Playground
关于xcode - 如何在 Swift Playground 中获取 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37919276/