简体   繁体   English

UIProgressView-进度栏-SpriteKit / Swift

[英]UIProgressView - Progress Bar - SpriteKit / Swift

I'm hoping to use a progress bar to denote a percentage in my App. 我希望使用progress bar来表示我的应用程序中的百分比。

I'm actually building it in Spritekit using Swift, so I'm hoping to do it programmatically, without the use of a storyboard etc. 我实际上是使用Swift在Spritekit中构建它的,所以我希望以编程方式实现它,而无需使用情节提要等。

I found this awesome tutorial , but unfortunately I can't seem to add it to my GameScene / worldNode... 我发现了这个很棒的教程 ,但是不幸的是我似乎无法将其添加到我的GameScene / worldNode中。

How can I create a progress bar and add it to my GameScene, inside my SKView/Gamescene (not via ViewController)? 如何创建进度条并将其添加到我的SKView / Gamescene中的GameScene中(而不是通过ViewController)?

Well, you could use UIKit to make a progress bar. 好了,您可以使用UIKit制作进度条。 UIKit, I believe, is imported with SpriteKit but if it's not you can always import it. 我相信UIKit是随SpriteKit一起导入的,但是如果不是,则可以随时导入。 You'd want to make the progress bar using UIProgress class: 您想使用UIProgress类制作进度条:

let prog = UIProgressView(frame: CGRectMake(your coordinates...))
//Set progress properties here (could also add a UILabel to show percentage from `progress` property
self.view.addSubview(prog)

The progress bar needs to be placed in the SKView of the scene. 进度条需要放置在场景的SKView中。 You can access it via scene.view if you don't otherwise have a handle on it. 如果没有其他处理,则可以通过scene.view访问它。

Here's an example in a playground: 这是一个操场上的例子:

//: Playground - noun: a place where people can play

import SpriteKit

let view = SKView(frame: CGRect(x: 0, y: 0, width: 400, height: 300))
let scene = SKScene(size: view.frame.size)
view.presentScene(scene)

let progressView = UIProgressView(progressViewStyle: UIProgressViewStyle.Default)
progressView.center = CGPoint(x: 200, y: 150)

view.addSubview(progressView)
// alternately scene.view.addSubview(progressView)

progressView.progress = 0.5
view

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM