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

Remove line break in UIActivityViewController
How to take NSRange in swift?
UIAccessibility in gridView - doesn't see new cells
swipe to delete uitableview cell [duplicate]
Changing Label Text & Colour Depending On Current Time
Ionic 2 cordova-plugin-mauron85-background-geolocation Not Updating UI
NSURLSession error when uploading on WiFi: NSURLErrorDomain Code=-999
iOS Observe absolute scale on CALayer in hierarchy
iOS adjust UICollectionView Insets after hiding Navigation Bar
Check if phone is face down
IBOutlets getting nil when dismissing viewController
Cant find Accella Mobile SDK IOS
How to create a custom UISlider
how to dismiss a UIView when tapped outside its bounds?
Swift: Reverse order or progress bar
Instantiate view controller from storyboard in second project in workspace

Categories

HOME
validation
opencv
web-services
dicom
angular2-forms
elf
azure-search
orbeon
configuration
android-activity
spring-roo
jsessionid
bolt-cms
genetic-algorithm
spi
telerik
microsoft-dynamics
akka.net
autofac
drag
identifier
google-weather-api
threadpool
openmodelica
sonata-admin
embed
atmelstudio
formio
co
ormlite-servicestack
django-autocomplete-light
memorystream
mediacodec
buffer-overflow
bluebird
nest-thermostat
panel-data
pvlib
google-crawlers
presto
jdom-2
paypal-rest-sdk
msal
cookiestore
runc
bem
procobol
mobile-browser
arm7
vega-lite
notimplementedexception
libev
paypal-webhooks
cabal-install
shift-reduce-conflict
django-errors
angular2-rc5
post-increment
cglib
finalcut
scrutinizer
groupbox
vimeo-ios
python-dragonfly
wchar-t
interpreted-language
mtp
crosswalk
axlsx
avalonedit
realm-list
data-science-studio
odoo
antiforgerytoken
wso2as
android-design-library
tortoisecvs
computer-science-theory
clearcase-remote-client
eventmachine
sonata-media-bundle
cfile
xidel
couchrest
str-to-date
libnids
mosek
hogan.js
double-precision
osmf
domain-mapping
jscience
bapi
data-oriented-design
facebook-authentication
blackberry-jde
cluetip
rails-3.1
syncml
spquery
sloc
plumtree

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