xcode - 如何在 Swift Playground 中获取 Canvas

标签 xcode swift swift-playground

我想要一张可以用来画画的 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/

相关文章:

javascript - 无法使用来自 JavaScriptCore 的 Swift 类

swift Playground : Indexing a List within a class gives an error

xcode - 在不使用 Xcode 的情况下通过终端链接 objective-c 类文件

swift - 尝试播放声音时如何解决 "found nil while unwrapping optional value"错误?

ios - Firebase Auth 链接提供商 Google 登录问题?

ios - 没有数组从父应用程序发送到 Watch 应用程序

ios - UISearchBar 未从 UITableView 中过滤自定义单元格图像

ios - 无法从 Xcode 7.3.1 在设备 9.3.2 上安装应用程序

Swift 程序约束 view.bottomAnchor 导致问题

ios - 新的 Playground 文件有什么问题?