I have an objective-c question. I have an app that detects the rotation of the iOS device. I want to be able to have a timer started when the value is between two ranges. Basically if the rotation is between 0.1 and -0.1 then the timer will trigger.
I have tried while loops, for loops and I'm sure it is som开发者_如何学Cething simple I need to implement.
Thanks in advance for the suggestions!
-Brian
Regarding your comment, it looks like you might have the logic reversed.
You had:
if (rotationValue >= 0.1 && rotationValue <= -0.1) {
// doSomethingHere;
}
If you're looking for when the "rotation is between 0.1 and -0.1 then the timer will trigger", then you'd want:
if (rotationValue >= -0.1 && rotationValue <= 0.1) {
// doSomethingHere;
}
(I switched the order around, putting the negative on the left and the positive on the right, as that seems more logical to me, but anyway).
Or you could do:
if (ABS(rotationValue) <= 0.1) {
// doSomethingHere;
}
Take a NSTImer
if you are entering that range (just store a bool for that) you create a new timer using
[NSTimer scheduledTimer...]
and if you are existing that region you will need to invalidate
your timer.
精彩评论