Pin Button on 3d Object in ARkit - ios

I am trying to Pin button on a 3d object. When the TouchBegan function loads, I use touch to place object in the world. I want the buttons to be pinned on the object when i load the object.
I am unable to find AR Button in arkit. All i can found is to place text as child node and name the node and get the first hit result and get the child node by name to triggers buttons.
The Button placing to object with relative to 3d space is an issue. Looking for possible solutions.
This is what i wanted to achieve and currently am using the github project as a demo.
https://github.com/eh3rrera/ARKitSceneKitExample

I suggest using box/plane with SKScene as material for button and text in SKScene as title. Then you can use hitTest in tapGesture. And maybe animate color change to have button pressed effect.

The way I solved the button problem in ARKit wast to create a physical button as part of the 3D model
you don’t need to create buttons with text, for say tapping open the door or switching a light... but you need to somehow communicate to the user they can tap (the door to open or tap a light to switch on).
To active the node you give it a unique node.name “front_door”
node.name = “front_door”
One downside is you have to do naming of nodes using xcode before the program is executed.
Below is the swift code for responding to the tap on the button on the door... using a hitTest. The door would rotate open when the button was touched.
let tappedNode = self.sceneView.hitTest(gesture.location(in: gesture.view), options: [:])
if !tappedNode.isEmpty {
let tappedName = tappedNode[0].node.name
if tappedName == "front_door" {
let doorNode = self.sceneView.scene.rootNode.childNode(withName: tappedName, recursively: true)
// rotate the door open
doorNode?.eulerAngles = SCNVector3Make( 0,0,Float(2*M_PI))
}
}

Related

In ScrollableGraphView, how to detect dot click from line graph and bar click from bar graph?

I already implemented ScrollableGraphView in my app, but I am not getting how to add label with value on click of "Dot" and/or "Bar". Please refer image.
and
Till now I able to achieve everything without label. This is best library.
But now I am not getting how to detect touch/click of Dot and/or Bar.
You can identify point of Tap via CGPoint : that will give X and Y Coordinates.
Location Reference: How to get a CGPoint from a tapped location?
For the label you want to show on tap, you have to
create a custom view using XIB and Invoke
it in Tap gesture Action/Selector.

Send double tap to SCNView

SCNView build camera control has a function,double tap sceneview and roll back camera to start position when allowsCameraControl is enabled.
i went to add a button do the same thing
when user click the button i will roll back camera to start position
there is no class implement UIControl in scenekit
so i can't use sendAction
i can set camera position by scnView.pointOfView
but there is a animation when user scroll the camera, set camera position will fail when animation is running.
is there a good way to reset the camera ??
NicoS's answer effectively handles the part of your question about making a user action change the camera POV.
As for your issue with undesired animation when setting pointOfView — you can control that animation (and any other implicit animations that happen when you change object properties) using the SCNTransaction class. To make a change with no animation, just do this (Swift 3):
SCNTransaction.begin()
SCNTransaction.animationDuration = 0
// perform your changes...
view.pointOfView = newCameraNode
// ...and anything else you want to happen in the same non-animated update, then...
SCNTransaction.commit()
Just add a TapGestureRecognizer to your Storyboard, to the view that has the SCNView. Connect the gesture recognizer action to your class so that you have an IBAction. Set the number of taps to two taps in the Storyboard Attributes Inspector. Now you can add your code to reset the camera.

control multiple buttons with one swipe gesture swift

I have array of UIImageView that printed on the main View (as subviews) in a matrix.
That UIImageViews interact while I am tap on them (work like a pixel when I touch one of them it turn on (move from black to green)
but I want to do it with swipe gesture so i can with one swipe trigger more than one "pixel" (UIImageView)
I found this for android triggering-multiple-buttonsonclick-event-with-one-swipe-gesture
and I wonder if there is something like that in ios with swift that recognise general touch (not tap or swipe) so I can looks for it.
The main purpose of all of this is to draw "shapes" on matrix of pixels with one swipe gestures.
If there is another way that you think will help I will be happy to here about it.
Many thanks
You are looking for the UIGestureRecognizer.
With this you can add many types of gestures, as swipe, touch..etc.
You can also get position, duration, and basically all the information about it.
You can check step by step tutorial in this link.
http://www.raywenderlich.com/76020/using-uigesturerecognizer-with-swift-tutorial
And also in the apple documentation.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIGestureRecognizer_Class/
i Manage to do the the swipe action using touchesMoved and touchesEnded
while the main idea is to invoke the UIIMageViews using the Coordinate of the touch and compare it to the to the UIImageViews Coordinates in the touchesMoved function
using flags to disable already edited UIIMageViews (while i am in the same touch session , the finger still on the screen) and refresh the UIImageViews to be editable again in the touchesEnded
func swipeTouches(touches: NSSet!) {
// Get the first touch and its location in this view controller's view coordinate system
let touch = touches.allObjects[0] as! UITouch
let touchLocation = touch.locationInView(self.view)
for pixel in pixelArrays {
// Convert the location of the obstacle view to this view controller's view coordinate system
let pixelViewFrame = self.view.convertRect(pixel.pixelImage.frame, fromView: pixel.pixelImage.superview)
// Check if the touch is inside the obstacle view
if CGRectContainsPoint(pixelViewFrame, touchLocation) {
// check if the pixel is Editable
if(!pixel.isEditable){
let index = pixel.index
pixelArrays.insert(updatePixel(index) , atIndex: index)
}
}
}
}
the only problem that i have now that if the swipe begin on one of the UIImageViews the touchesMoved function consider it the the view to looks for the coordinate and the other UIImageViews are not effected
my idea to solve it is to add layer on top all of the UIImageViews and disable the tap recognition that they alredy have and implement the tap also with the Coordinates way.
i will be happy to hear if there is another way to do it
Update :
i mange to solve the problem above by sort of what i wrote but instead of add another layer i disable the touch on all of the UIImageViews and invoke them using the Coordinates of the touch and them
many thanks

Building a tower defense game. How do I add a circular menu with tower choices on tile Node in SpriteKit?

I'm building a tower defence game using SpriteKit and I'm relatively new to this.
My map basically consists of tile Nodes that are touchable. Once a user touches the node, I can place a tower on that node (I have this part working so far). What I want to do moving forward, is instead of directly placing a tower, I'd like a circular menu to pop up around the tile Node to let the user pick the tower that they wish to place in this tile node.If the user clicks anywhere other than the circular menu, the menu should disappear.
So something like this:
http://imgur.com/QvCsM8Q
I'm wondering what the best way to do this is. I have two possible solutions but they seem hacky:
1) Creating a custom UIView consisting of the menu and 4 buttons and then adding it to my scene (but then how do I detect button presses in this menu from the scence?)
2) Extending a SKShapeNode to create a circle and adding in 4 SpriteNodes around the circle, then verifying if a touch location corresponds to one of the 4 SpriteNode locations.
Any suggestions/code examples of how best to approach this?
I would suggest you create a separate class for your tile nodes (which inherit SKSpriteNode) and add the functionality within that.
For the approach for the menu, I think something along the lines of point (2) would be better. By subclassing the tile node, you can make the tile detect the selection by itself.
Expand the tile using SKShapeNode or a SKSpriteNode with a circular image using animation.
Place the four buttons on the expanded part.
Implement the touch for the selection within the tile node class.
For closing the menu, a tap on the scene can trigger a NSNotification for which the tileNode could become a listener on expansion.

UIButton detect press and hold, along with "gesture recognizer"?

I'm trying to figure out how to detect a press and hold, as well as a gesture recognizer on a UIButton.
I did search around and didn't find exactly what I was looking for.
Here is a quick gif to see what I'm trying to do: http://blitzzmobile.com/files/button.gif
(in the case of the gif the user holds on the "5" button and drags up to select the addition button.)
If anyone could give me a tip or point me in the right direction it would be greatly appreciated!
Edit : Also, I'd like to know if its possible to detect the location of the "drag" and animate accordingly. (Example: if someone drags half the distance to show the new menu, the menu animates accordingly) & the method to detect the drag release, not from the UIButton, but when the user lifts his finger after touching the UIButton and dragging, an action is called, is this possible?
For whoever might benefit from this, here is what I did:
-(IBAction) yourAction:(UISwipeGestureRecognizer *)recognizer{
if(yourbutton.highlighted){
//Do your animation/setup here.
}
}

Resources