How to get a Canvas in a Swift Playground

痴心易碎 提交于 2019-12-05 00:11:18

问题


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.


回答1:


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) 

UPDATED

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



来源:https://stackoverflow.com/questions/37919276/how-to-get-a-canvas-in-a-swift-playground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!