Hey what's up everyone.
Mark Price you're at death's slopes dot com and let's see if we can't finish up this video or this app.
And in this video and what we have left to do is I want to implement some controls where you can where
you can manipulate and move things around and move them up and down and such.
And then some other cleanup.
So first clean up I want to do is in the ramp picker when we select a ramp here I want to go ahead and
dismiss the View Controller so dismiss animated.
Yes.
We don't care when it's done.
So that'll go away once we've selected something and then the other thing we want to do is get back
in place or we're going to need to store a reference to our ramp now because we need to be able to move
it around and delete it.
And so what I want to do here is selected ramp.
That's funny we should probably call this select the ramp name.
That's what we should do.
And then make the selected ramp the actual Selecta ramp.
So wherever I found.
Come on name select that ramp name.
There it is.
This one selected ramp name.
And this one is selected ramp name.
OK.
Perfect.
Very good.
And let's go ahead and criticize the ramp.
Now our selected ramp of type C and node j like so perfect.
And then when we actually slide the ramp.
So Or is it down here.
We're going to say selected ramp equals ramp.
We're just going to store reference to it right here like so now let's go ahead and do the user interface
for our cool little controls.
So we've got our button over here.
What I want to do is put four buttons here and then probably put them in a stack view that makes the
most sense.
So we're going to save button.
And what I'm going to do is take off the word button and we're going to set an image here and let's
call this the close by.
And now not the close button the remove but an removed but that's what we want and I'm going to go ahead
and let's make this little bit bigger like so so it's actually tabel a little bigger.
The buttons the same size but I'm making the bounding box bigger.
And let's go ahead and set a constraint on this.
We're going to say Fix width and height and we'll just say 41 by 41.
That's fine.
Now what I'm going to do is duplicate this three times.
One two three and then this one will be the rotate by an like so this one will be the move up by an
up arrow and this one will be the down arrow we can find the down arrow.
Perfect.
Now what I'm going to do is just simply shift select all of these and put them in a stack by clicking
this button here embed and stack.
And now what I want to do is distribute feel equally.
Let's go ahead and add some spacing.
Make it larger there.
And what I want to do is just move it to the same bottom portion of the view as is match with this button
and let's set constraints on the stack.
And I want to say 10 from the left and 10 from the bottom and there are buttons which is pretty cool.
No big deal you've done this before.
A thousand times.
OK.
So what do we want to do.
Now what we've got is four buttons right.
And you maybe you're thinking well let's just IAB actions for all four what we can't.
We just had an IB action for the delete button because it's just a tap.
But what we want to do is when we're rotating or when we're pressing the rotate but we want the ramp
to rotate so long as we're pressing it.
It's a little more difficult and you can't really do that with reactions easily.
And then the same thing for the up and down but when you're pressing it we want to move the ramps.
And so what we're going to need to do instead is use gesture recognizers but we will need to make Iby
outlets for these.
And one Iby action for the red button.
So let's open up the assistant editor by clicking the two circles there.
And what we're going to do is I'm going to create an action down here for the close button
so grab this close button or the Remove button and we're going to create an action say on remove and
remove preste.
OK.
So that one's done.
So I think we're OK now in Interface Builder.
Let's go over to the well you know what let's keep a reference to the stack as well too.
Because what I want to do is if you haven't selected a Rampa I want to hide this.
I don't want a stack of you to be visible.
So first make a hit.
And then what we'll do is we'll make an outlet for it over here.
All right so this is going to be our controls.
There we go controls ibl outlet close the assistant editor and let's go back to a ramp place Ribisi.
Ok cool.
So let's just do the easy one first which is the removal right.
So let's go over here on roof press.
So what we'll do is we'll say if the left ramp equals.
And we're going to say selected ramp.
So if there's a selected ramp OK well we want to do is just remove Right so ramp up remove from parent
node and we'll say ramp or a selected ramp equals Neil.
OK we'll make it the one that we're referencing up at the top of the pile here.
We'll make it kneel after we remove it.
No big deal.
And if left is good because it could be nil and we don't want our app to crash so that's good and move
press.
Now how do we do the hard part.
The actual button presses.
So what we're going to do is we're going to go up here to our view did load.
All right.
And we're going to need to create some gestures now.
Unfortunately we can't just use one gesture for all the buttons.
We're gonna have to create three different gestures.
And the reason is normally you could you could create one gesture and add it to multiple views.
And so long as you're just using the view to detect when a tap happens that's fine.
But what if you need to reference the view that actually caused the tap to happen.
Well if you use one gesture recognizer every time you add it to a new view it replaces that view.
And so what we need to do is create a new gesture recognizer for each gesture.
Trust me you have to do it this way if you don't believe me just use one just to recognize or try it
out and see what happens.
So a gesture one equals UI a long press gesture recognizer and the target is going to be self and the
action is going to be what.
Well we didn't create one yes let's do that now.
We're going to say what we want to call this let's say at BJC because it's just an object to see runtime
function.
We're going to say phunk on long press.
And the gesture is going to be of type long press gesture trochaic Nizer and that's what we use.
Let's go back up here to the top and the selector is going to be worth my auto complete Where's my complete.
It's not working for us that's fine.
So like there's going to be on long press you go now.
Now it came to our aid.
All right.
Great.
And so what we're going to do is just copy and paste it two more times.
I know it sounds like it's the wrong thing to do but it's not because each gesture needs to hold a reference
to its own view a gesture one gesture to gesture three and then we're also going to use a gesture one
at minimum the minimum restoration equals 0.1 we're going to make it really small like a small long
press because we wanted to start working right away.
Copy this two more times.
I know it doesn't seem very dry.
Don't repeat yourself.
This is the way we got to do it.
And then let's go ahead and say rotate and add gesture recognizer and he did the image.
That's funny.
Rotate all right.
Now do we not make her Iby outlet's Oh we didn't.
Guys what the heck why don't you tell me we didn't make her ideologies.
I said we were going to do it.
But then we didn't.
Silly me yes proben waiting this whole time.
When are you going to do it.
All right so control drag and this is going to be called rotate DTN so names exco drives me crazy.
Just give me random errors is all OK.
Control drag.
And we're going to call this rotate button.
All right.
Sometimes when they're all close together like that and you direct control drag it throws an error.
So this one we're going to call them we'll call this up button.
Yeah.
And then what we'll do is we'll make a new one called Down button
down between.
OK now we're good.
Let's close the assistant editor and go back into our rant placer.
Wonderful.
Now we can say rotate DTN add gesture recognizer gesture one and then we're going to say up between
dot and gesture recognizer gesture to and then down and add gesture recognizer gesture three.
I know it's a lot but we're getting close.
So we're just adding gesture recognizers for each of these views.
And this looks good to me.
Now go down here to our on long press.
What do we want to do.
Well what we want to do is if.
So basically whenever a long press is happening we want to detect when it started.
So we also want to detect when it ended if it if it began.
We want to go ahead and what we want to do is run an action forever it's going to move it down forever.
So what's funny is when our fingers down the fact that the fingers down doesn't really matter it's not
we're kind of secretly doing something under the hood we're actually doing an action forever.
But we also detect when your finger comes up and then we stop the action.
Right.
So we don't have to do any complex math anything crazy.
We just got to use our brains to do something smart and we're going to some smart.
So no big deal.
So on long press if left ramp equals ramp is selected ramp.
OK.
So let's make sure that we actually have a ramp to actually manipulate with the controls.
And then what we're going to do is we're going to say if a gesture does state equals that ended OK if
it equals that ended what are we going to do.
Or to say ramp up remove all actions.
And what equals is what I meant to do.
This is not javascript.
OK.
Else if just your state equals began.
What do we want to do.
Well first off we need to see which button was pressed.
OK.
So that's easy.
We just need to run some up some some reference checking.
So what we're going to do is we're going to say if gesture that view equals the same do use the triple
equal sign.
Ok rotate button.
OK.
So if you are kind of new to swift and you're diving into this more complex topic of augment or of your
augmented reality what's the difference between a double equal and triple.
Equals well a double equal is just checking type and value.
OK a triple equals is actually checking the reference.
So what we're doing is we're saying we're actually grabbing a memory location and checking it against
this memory location.
You know you know x x 0 x whatever this memory slot we're seeing if it's in the same slot in memory.
So is the view that the gesture is on the exact same view as the rotate by.
And we know that rotate was pressed.
OK remember we couldn't do Iby actions for those buttons where we we we we just know it was pressed
because what we wanted to do was detect when it's a long press down.
And when the finger comes up we had to use gesture recognizers.
And so we're checking the reference in memory of the view that matches the gesture and making sure it's
attached.
So if the view that was just pressed is the rotate button that's all we're saying here as if it's the
same one in memory.
Ok then let's just go ahead and rotate.
So let rotate equals CNA action that repeat forever like so.
See an action rotate by.
And we're going to say zero.
And on the why we're going to say full light and where to say zero point is 0 8.
So a number that I tested out times double dot pi k and Z we're not going to rotate at all.
And the duration is 0.1.
So it's very similar to the code we wrote to rotate before except this one is faster.
We want it to rotate faster when we sit there holding it down forever.
So rotate and there were a ramp that run action or cirrhotic.
So when the finger comes down on the road Taban start action that goes forever.
It rotates forever.
And then of course when your finger comes up we just remove the action.
So it simulates like your finger being down is actually actually moving something when it's really not.
It's this action here that we started once and once.
So if you gesture that view equals the up button.
OK.
What do we want to do we want to move it up.
So let move it was as an action.
Repeat forever.
And action that move by.
And we're going to say zero Hoopes.
We're going to say
an action that moved by.
I did it wrong.
My bad move by.
That's the one we want.
And then we went to zero and then negative zero point zero eight for the speed and the Z is going to
be zero and the duration is 0.1.
OK.
So that's the.
Well not negative.
This would be down.
So eight points or eight would be up.
OK.
And then we're to say ramp up run action and we're going to say move.
OK.
And then we're going to say LCF gesture that view equals down button.
We're going to copy this Lexow and then we'll add the we'll add the negative.
The mind is simple there.
OK.
So when we start rotating let's run.
Repeat for every rotation action if or up or down.
We just wrote all this code and then when we remove all the actions and that's on a long press we added
the recognizer So technically this would all work out of the box for us here.
Let's see if it actually does.
So let me go ahead and run the app.
OK.
So the app is running and I'm recording it and here I'm going to press the button and I'm going to select
the pyramid I'm going to tap and the pyramid is there.
But my crew controls didn't appear and that's because we forgot to unhide them.
So let's go back over here to our place ramp.
Perfect and what we want to do is just say controls dot hidden equals hidden equals false.
And let's go ahead and run this again.
Running it going to select the ramp in a tap to place the ramp is there and the rotate button that's
working.
I don't press the down button.
And that's working and the Upperton is working as well.
Let's see if the Remove button is working which it is.
Let's see if we can place another ramp.
There's a quarter pipe way up there too.
I placed that one up there which I can't delete now.
That's a feature upgrade you can add let's move it down here.
Yeah.
So it's definitely working.
Very very cool.
And let's just make sure our half pipe is working I'm deleting that
and that's working to look at that.
Now of course we need to really be outside to do this.
And
to see what it's going to be like the scale and everything.
And currently where I live it's dark but we've already seen what it looks like here on the privey video.
So I did this earlier show that here.
And cool.
This is really cool.
How do we do one more thing.
We just clean up our our pop up.
I don't like the fact that there's no border on our rent picker pop up.
Let's just quickly have some fun with that so wrap picker ramp picker here and let's just do it in here.
So what we're going to do is we're going to see you flared up border color equals color literal white
is fine and then view layered up border with ECOs 3.00 just make it look nice and pretty.
Here we'll do on the simulator this time and run it.
OK we're not going to see anything obviously because it's not working.
Click the invisible button.
And there's definitely a border on here.
So that's what we want and it looks really good with our camera in the background so that's it we're
going to call this video done.
So what we've done here is we've created our very first aid kit app.
OK.
We are working.
We basically have a pop up that appears where you can select one of three models and then we select
that dismiss the pop up and we can place it on the screen using the screen or the surface detection
technology and you learn how to do that.
And there's so much more to a market to learn.
But we've done a lot here and you can move things around in the 3-D space and it tracks where they are
so you can actually walk around and turn your phone and still be there.
Which is pretty dang cool.
Imagine all the things you could do you can make a 3D game with the Worlds and environments and walk
around and have enemies and everything stays in place.
Really cool stuff with the service technology of course that's really important.
Used to have to use your coach right to detect the surface.
Now it actually does the surface detection real time which is amazing so really good stuff here we've
done a lot.
It can get complex but this is a good step in the right direction for you in your adventures in air
kits.
That's it.
Marc price you're a Dove soaps dot com.
See you next time.