如何在 Swift Playground 中获取 Canvas [英] How to get a Canvas in a Swift Playground

查看:37
本文介绍了如何在 Swift Playground 中获取 Canvas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一张可以用来画画的画布.目标将是基于 iOS 的 Swift 游乐场.我搜索了文档,但找不到名为 Canvas 的对象,但如果有类似的东西,那么它对我也有好处.

I would like to get a canvas that I can use to draw on. The target would be an iOS based Swift playground. I searched the documentation and I could not found an object named Canvas, but if there is something similar to it then it would be good for me as well.

推荐答案

你可以使用类似的东西,注意你不必使用 Sprite Kit 类.

You can use something similar to this, note you don't have to use Sprite Kit classes.

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

I've created a wrapper class to make this easier for everyone. Download the Playground here on github

这篇关于如何在 Swift Playground 中获取 Canvas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆