ios


Swift convertPointFromView returns NaN when move back from child view


I am working on a tutorial part of a game. When instruction button clicked, screen will move from SKScene to UIViewController for a tutorial. The problem is my SKScene works fine before tutorial, however when come back from the tutorial, the node can't be clicked.
This is the code to move to tutorial from SKScene:
let a = (self.view?.window?.rootViewController)! as! GameViewController
self.willMoveFromView(self.view!)
self.view?.removeFromSuperview()
a.showInstruction()
Method showInstruction in GameViewController:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let tut = storyBoard.instantiateViewControllerWithIdentifier("pvcTutorial") as! Tutorial
tut.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
addChildViewController(tut)
view.addSubview(tut.view)
tut.didMoveToParentViewController(self)
Here is code to move back to SKScene from tutorial:
self.parentViewController?.view.removeFromSuperview()
self.parentViewController?.removeFromParentViewController()
self.parentViewController?.willMoveToParentViewController(nil)
The reason I am using parentViewController is because I use UIPageViewControl for tutorial. The code will remove the UIPageViewController to get back to GameViewController.
How I use detect node from SKScene
var loc = tap.locationInView(tap.view)
loc = self.convertPointFromView(loc)
let btn = self.nodeAtPoint(loc)
if btn is SKLabelNode{
if btn.name != nil{
if unlockLevels.contains(btn.name!){
let gameScene : GameScene = GameScene(size: size, difficulty: btn.name!)
let reveal = SKTransition.crossFadeWithDuration(NSTimeInterval(2))
self.view?.presentScene(gameScene, transition: reveal)
}else{
if btn.name == "instruction"{
let a = (self.view?.window?.rootViewController)! as! GameViewController
self.willMoveFromView(self.view!)
self.view?.removeFromSuperview()
a.showInstruction()
}
}
}
}
The solution I made is just simple that, instead of:
let a = (self.view?.window?.rootViewController)! as! GameViewController
self.willMoveFromView(self.view!)
self.view?.removeFromSuperview()
a.showInstruction()
I changed it to:
let a = (self.view?.window?.rootViewController)! as! GameViewController
a.showInstruction()
And it worked! As far as I understand is that in my previous code I wrote made SKScene removed from the GameViewController. However, I am still confused that why the scene was still able to show as nothing happened but just unable to touch any node on it. Anyways, the problem fixed and any explanation would be appreciated.

Related Links

How can I get indexPath of a uiview on a cell - iOS
How to allow audio to continue to play when app is backgrounded?
How to limit the pulling distance with a refresh control?
Image fits into UICollectionView Cell
Caching the downloaded data
Core Location and Google Maps
(Objective C) NSDate is nil to convert a date in String
Swift need to reload TableView that is contained within a containerView
Remove iAds from SKScene
Adjust UICollectionView Size Dynamically to Ensure No Inter Item Spacing
How to replace Detail in UISplitViewController in Swift?
Adding Delay In A For Loop Without Blocking UI
Swift 1/2 UITextView suggestion by tag “#” or “#”
UICollectionViewController that looks like UITableViewController
iPhone simulator screenshot is not in proper dimension
How to update app via Xcode 5.1.1 for iOS 9

Categories

HOME
opencv
demandware
web-applications
magento
codenameone
elf
weight
antlr
windows-server-2012-r2
classloader
microsoft-dynamics
activerecord
asciidoc
cross-compiling
executable
chart.js2
highlight
graph-tool
phpbb3
curve-fitting
swig
git-bash
smartcard
opencms
similarity
centroid
addthis
epicorerp
weather-api
listbox
sumifs
arduino-esp8266
rdf4j
python-behave
udid
powerbuilder-conversion
increment
packaging
knowledge-management
amazon-vpc
mindstorms
internet-explorer-10
mdanalysis
android-calendar
reactivex
billing
easyhook
android-sdk-tools
building
data-fitting
skrollr
filenet-content-engine
document-ready
jedi
ospf
sejda
ironmq
node-orm2
cvc4
simperium
excel-charts
information-schema
mui
bessel-functions
controlsfx
tinkerpop-frames
grunt-contrib-copy
windward
xsltforms
dotliquid
ramdisk
glulookat
broadcom
repeating
rcu
mainwindow
adlds
argumentexception
square-cube
jmdns
eject
jcycle
browserid
android-actionbar-compat
datakey
google-profiles-api
consistent-hashing
stumbleupon
eye-detection
keylogger
scramble
pinging
sqlitemanager
clipboard-pictures
roguelike

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App