My app is running Spritekit and is designed for Landscape orientation only, and I can't for the life of me figure out why when I present the modal view for authenticating a player in Game Centre, the keyboard is missing.
Here is my code at the moment.
class GameViewController: UIViewController, ADBannerViewDelegate, GKGameCenterControllerDelegate {
var gameCenterEnabled: Bool = false
var initialized: Bool = false
let leaderBoardIdentifier: String = "squareBeatLeaderboard"
@IBOutlet var bannerView: ADBannerView!
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
// Configure the view.
if initialized == false {
let skView = self.originalContentView as SKView
let scene = GameScene.sceneWithSize(CGSize(width: self.originalContentView.frame.size.width, height: self.originalContentView.frame.size.height))
skView.ignoresSiblingOrder = true
scene.scaleMode = SKSceneScaleMode.ResizeFill
self.authenticateLocalPlayer()
skView.presentScene(scene)
initialized = true
}
}
func authenticateLocalPlayer() {
let localPlayer = GKLocalPlayer()
localPlayer.authenticateHandler = {(viewController: UIViewController!, error: NSError!) -> Void in
// handle authentication
if let viewController = viewController {
self.presentViewController(viewController, animated: true, completion: nil)
//keyboard
NSLog("log the user in") // why the hell is there no keyboard
} else {
if GKLocalPlayer().authenticated == true {
self.gameCenterEnabled = true
} else {
self.gameCenterEnabled = false
}
}
}
}
The 'initialized' boolean is to make sure the set up isn't loaded again when my iAd refreshes.
When the Game Centre login view comes up, it looks all fine except for the fact that the keyboard isn't in the correct place. In the iPhone 4S simulator, this is what happens: http://i.imgur.com/TJjfYq2.png
This looks like a rotation error. Like the keyboard is presenting coordinates from portrait, but the view is in landscape. If your app is set to only be on landscape in the info.plist file, then you must be overriding it somehow. If it is not set there, then I would lock it down, unless you need portrait orientations.
The fix for when you have mixed orientations but somehow a view has the presentation incorrect, force the landscape mode for the view by setting the orientation mask:
Tutorial here:
http://makeapppie.com/tag/uiinterfaceorientationmask/
Other code examples can be found within the Ray Wenderlich tutorial below. Download the starter project:
http://www.raywenderlich.com/82022/create-game-like-cut-the-rope-using-sprite-kit-swift
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.