Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hittest does not detect geometries hidden behind others in ios11 - swift

I couldn't get hitTest (with no options) to detect geometries that are hidden behind some other geometry in iOS 11. My code worked fine on iOS 10. Anyone know how to fix?

Example: let hitResults = scnView.hitTest(location, options: nil)

Should return several nodes - but does only return one node.

like image 349
Bernd Avatar asked Dec 14 '22 20:12

Bernd


2 Answers

You should use the symbolic constant SCNHitTestSearchMode.all instead of 1, it's more descriptive.

if #available(iOS 11.0, *) {
    hitResults = scnView.hitTest(location, options: [.searchMode: SCNHitTestSearchMode.all.rawValue]) }
}

The other options are .closest and .any.

like image 102
Ortwin Gentz Avatar answered Dec 16 '22 10:12

Ortwin Gentz


Adding some additional details - in my experience, there has been a major change from iOS 10 to iOS 11 in the way SceneKit handles touches. Specifically, the DEFAULT operation in SceneKit, as Bernd notes above, is now that only the first node touched in the "ray" is returned in the [SCNHitTestResult].

The additional comment is that if you were hoping for backward compatibility to iOS 10 or before, I couldn't seem to get it to work, because the solution noted above requires iOS 11 Deployment Target. So Apple seems to have changed the default way touches are handled, and if you want it to work the original way, you must change the default of [SCNHitTestOption.searchMode : 1], which is only available if/when you change your Deployment Target to iOS 11 or higher. ( thanks, Apple)

Here are some futher oddities I found as I searched for a way to make an iOS 10 deployment work with Xcode 9 / iOS 11 updates. (note: I had upgraded my phone to iOS 11 when testing these scenarios with an iOS 10.3 Deployment Target build)

  1. the [SCNHitTestOption.firstFoundOnly : 0], while available with iOS 10 deployment, seems to be ignored if .searchMode isn't also set to 1, which requires iOS 11
  2. similarly [SCNHitTestOption.categoryBitMask : ], while avail with iOS 10 deployment, seems to be ignored if .searchMode isn't also set to 1...

Bottom line, from what I can tell, is that Apple does everything in its power to force devs to upgrade to the latest OS (either wittingly or unwittingly), which then "encourages" end users to have to upgrade to get the latest app updates.

like image 35
Eric Avatar answered Dec 16 '22 09:12

Eric