Welcome, iOS developers.
For today's Quick Tip, I want to show you this cool new drawing
app I just made, Pressure Draw.
It is a simple drawing program with one little twist.
If I touch the screen lightly, it
makes a thin line, like this.
But if I press harder on the screen,
it makes a thicker line, like this.
But wait a second, iPhones don't have pressure
sensitive screens, do they?
So how did I do this?
Did Apple give me a top secret prototype
iPhone with a pressure sensitive screen?
No, no.
They didn't do that.
Why would they even-- no.
The answer is that I'm taking advantage
of a new UITouch property in iOS 8 called majorRadius.
You can think of majorRadius as basically a measurement
of the size of the touch that the screen receives.
I'm using it here to approximate touch pressure
because, for human fingertips, they tend to squish
and the touch circle gets larger the harder you
press against things.
Note that this doesn't work in the simulator
or if you have metallic fingers.
Sorry, Iron Man.
But for the rest of us, it does work, kind of.
The problem that I'm running into
is that the granularity is pretty crude right now.
The smallest radius I get is this 25.52429.
Then it goes from there to like 38.29.
And then 51 point something.
I can get to some higher numbers if I touch the entire phone
with my palm.
But that's kind of it.
For a single finger, there's no real variation
in between these numbers, which is weird
because these super precise floats kind of suggest
there should be, right?
So if I turn off my little bit of LERPing between major radius
sizes-- yes, LERPing is a thing.
Google it-- you can see that the jumps in between my brush size
are actually pretty abrupt.
So in practice, I'm not sure I would use this
for a real drawing program.
Sorry, Pressure Draw.
You will never see the light of day.
So where could you use it?
Well, you could certainly use it for nonessential UI polish
tweaks.
Do you have a particle effect that goes off
when the user presses a button?
Well, you could use the majorRadius value
to determine just how many particles you shoot off.
Whoo-- that was a lot of dollars.
Or you could change the volume of the sound that accompanies
the effect, or both.
I kind of wonder if you could use this as a poor man's force
touch.
This is a UI pattern that Apple's
looking to establish on the Apple watch.
And maybe this is sort of a jerry-rigged way
to apply this to devices that don't have
pressure sensitive screens.
But frankly, I'm not sure about this one, yet.
That's why you got a big question mark here.
I would say proceed with caution.
Honestly, I think the best use of majorRadius
might be not to detect touch pressure,
but instead to distinguish big, ungainly fingers from thinner,
elegant fingers.
Here's the thing.
In games in particular, if you look
at a lot of the good, really high quality stuff out there
today on touchscreen devices, they
will cheat to make sure their players are
doing the right thing.
Here's a favorite example of mine.
This is the game 10000000, which you should totally
buy if you haven't yet.
It's on the App Store and the Play Store.
So check this out.
Here you can see I'm moving my piece
to a point where I'm really only about 30%
towards making a valid move.
But the game kind of nudges me a little bit forward so
that my piece settles in a place that makes a match.
And it works the other way, too.
Here I've overshot my move by about like 70%, right?
But once again, the game is cheating a little bit,
and settling my move back into a place that makes a valid match.
Isn't that brilliant?
I'll answer that for you.
Yes, yes it is.
This game is, nearly invisibly to me,
doing what it can to make me feel like I am a good player.
And it's these kind of design decisions that can make
the difference between a game that feels right and a game
that doesn't.
So tying this back in to majorRadius,
say you've got a game with a bunch of elements densely
packed onto the screen, maybe a grid based puzzler
or a hex-based strategy game, you can help out
your players by looking at where they touched
on the screen, and the size of their touch,
and then using a little logic to guess at what game element they
really meant to click on.
So even if I am playing your game with my big fat thumb,
I can still touch all of the right elements.
Anyway, those are just a couple random ideas.
I've asked around here.
And so far, we're only using majorRadius in one place.
It's basically a testing only feature
where we put up a little indicator that shows where
our testers touched on screen.
And we're using majorRadius to decide how large of a circle
to draw.
But if you end up using it in your code, please let me know.
I am dying to find out what you did.
You can put it in the comments below.
majorRadius appears to be supported
on any device that runs iOS 8 back to the iPhone 4S.
So there you go.
Thanks, again, to Dave Oster on the Google News
team for the tip.
But what about you?
Do have a tip that would make for a good Quick Tip?
Send it in.
You can email me at the address here.
If we use it on the air, I will send you a t-shirt, or maybe
a top secret iPhone prototype with a pressure
sensitive screen, but most likely the teacher.
Anyway, thanks again for watching.
As always, click here to see more videos from Route 85,
our show for iOS developers.
I will see you soon.
[MUSIC PLAYING]