3

I'm using Swift 5, SpriteKit, SKTileMap. I would like to use the equivalent of a popover. I'm using this term, because I use popovers rather frequently in other apps. Basically, a small window appears, and you read something and press OK, or maybe add a little information and press OK. What I'm trying to figure out how to do is something similar in SpriteKit.

The objective is, I want a user to long press a tile, and a small box pops up with information about the tile. What is the terrain? What resources are there? Is there a city? Is a player there? etc. It doesn't HAVE to be a view, but I'm guessing that's the way to go, because not only could there be quite a bit of text, I could see there being a button to dismiss, and maybe some tiny graphics, like a symbol corresponding to the resource, etc. Here's what I have already. I have a working long press gesture recognizer. I can already print all of the information I want to the console on the simulator. What I need to figure out is a few things.

  1. required: create the window and fill it with information.
  2. optional: anchor to tile and/or center in the screen. I haven't decided best solution yet.
  3. optional: dim background (probably just some alpha tweak)

The current code I have actually works very smooth. I have a good camera pinch to zoom and a good pan gesture. I load my map from a JSON file. I actually load it into a core data, database, and draw from a query against the database. That way, if you do any action, it just hits the database. What's on tile 5,5? just query the database. It works nice. I just don't know how to do the popover window in SpriteKit. I tried adding an actual popover to the content view my map is in, but it just dims the screen a little. I don't think that's a good anchor.

4

1 回答 1

1

在 HIG“人机界面指南”中,它们被称为“警报”或警报表,您可以使用简单的代码创建警报

let alert = UIAlertController(title: "Did you bring your towel?", message: "It's recommended you bring your towel before continuing.", preferredStyle: .alert)

alert.addAction(UIAlertAction(title: "yes", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))

self.present(alert, animated: true)

您可以从此链接了解更多如何编程、样式等https://learnappmaking.com/uialertcontroller-alerts-swift-how-to/

于 2020-09-06T03:34:18.927 回答