Sequentially "flash" UIButtons - iphone

I have a series of UIButtons from 0 to N with a background image which is a color. I want to take a sequence of numbers from 0 to N, run through it and flash the corresponding button for each number sequentially. I have thought of changing the background to white and using sleep, but I haven't been able to get it to work. The buttons must flash sequentially with equal time spacing between the flashes. Pseudocode is:
for(i in sequence){
[[buttons objectAtIndex:i] flash];
//The flash must complete before the next button flashes.
}
Is there anyway to simulate the same animation as a button press, because that would be perfect? Basically I'm doing these flashes to show the user the sequence in which to press the buttons, is there a more elegante way to do this? Should I use some custom view instead of UIButton (I need it to be clickable, but I could program that instead of using a button)?

NSTimer is your friend. Check up on the documentation for it. You could have it fire at a set interval and just increment the count each time it fires.
For animation look at the animation methods provided for in UIView's documentation. Should have everything you need.
DO NOT USE sleep under any circumstances. This will make everything completely non responsive while its sleeping. There are all sorts of other more useful methods that allow for delays.

Related

iOS Swift - How many UILongPressGestureRecognizers can be enabled at one time?

I have a simple synthesizer application that has 28 buttons (UIView's), and each one has a UILongPressGestureRecognizer attached to it. The .minimumPressDuration for each recognizer is set to 0, so that simply touching a button will begin it's UILongPressGestureRecognizer and start an AudioKit Oscillator.
All works fine until more than five buttons (recognizers) are touched (enabled) at one time. The sixth recognizer is never enabled, and the first five recognizers stay enabled, even when the user's finger lifts from any or all of the buttons.
It's an unfortunate problem, given that I would like the user to be able to play more than five notes at a time.
Any ideas?
I have attached UILongPressRecognizers to buttons that do not start an AudioKit Oscillator, but instead temporarily change the color of another view, but the problem persists.
I have also tried touching other areas of the screen that do not have UIGestureRecognizers attached to them, and even those touches seem to cause the problem.
There is an undocumented 5 touch limit on iPhone. The number is higher for iPad but I'm not sure what that limit is (greater than 10).

Animation Stickman

In my app I have a stickman, which moves to right when you click a button. Within that time (moving to the right) I want to animate 6 pictures, where you see the stickman running. The purpose of clicking that button is to do it as fast as possible, and I want to let the stickman finish running even when the user clicks the button again. It's a kind of a race to get at the finish as fast as possible. My purpose is to make the running of the stickman look natural, so the running doesn't start again when the stickman is not yet ready with his steps.
Is there anyway to do this??
Thanks in advance,
Joe
That should be very straight forward, just define a (global) variable or a class property that like status that you can set it to running or stopped and when the button is clicked check if (status!=running)
Does this solve your problem?
If you show us some code and point out the exact problem people could better help.
Try this...
say have an
UIImageView *imView1;
NSTimer *timer1;
count = 1;
say images have name as
img1,img2,...,img6 - PNGs.
inside the timer method:
{
count++;
[imView1 setImage:[UIImage imageNamed:[NSString stringWithFormat:#"img%d.png",count]]];
if(count==6) count = 0;
}
If you want to increase or decrease the speed, you can change the time interval. The loop will not break.

A method to override that gets called a couple of times a second? or a loop its safe to code into?

Making a simple card game, and it it should ok when the user is in control since he will push a button. It will call my method assigned to that button and logic will be performed and screen updated.
But when the players turn ends, and i want the AI to run everything for a few seconds, update the screen with its decisions etc. Handle some logic, call some animation before handing the control back to the user.
Is there a method i can override in my Controller class that which is a subclass of NSObject that gets called every loop or at least 5-10times a second? Or how is it you guys handle this?
Thanks
-Code
It doesn't seem like you want a background thread at all (at least not one you make) or a timer.
What you really want to to is visually animate the AI actions, to that end look at the CoreAnimation stuff, to define animations for AI actions and then play them. You can specify a time period an animation is to take.
Look at this project for examples of animation from the simple to the complex:
http://github.com/neror/CA360
Just create a an NSTimer that calls a tick method at whatever frequency you desire. But keep in mind that NSTimer is not guaranteed to be precise, so in order to avoid gradually accumulating errors, you might want to check how much time has actually passed (e.g. if the timer fires an average of 10 ms late over 500 ticks, code that depends on precise timing will be five seconds off).

Iphone default behaviors that need to be implemented?

When I've learned that I have to write some code to make the iphone keyboard go away. I was quite surprised. I was surprised even more when it become apperent that it is just the top of the iceberg.
What are the expected UI behaviors that aren't provided by system OOTB?
Is the list below complete?
The expected UI behaviors:
Focusing next text field when [done] is hit
Hiding the keyboard when background is hit
Using Touch Up Inside to fire a button action. (To give user opportunity to change his/her mind)
Supporting the screen rotation.
Some of that is silly, but some of it has uses as well.
Focusing next text field when [done] is hit
Which field is "next"? If you have a large form with fields both next to and above/below each other, next might not be so obvious. Even if they are in some linear layout, the iPhone would have to work to figure out which one is next. Do you want to wrap around at the end of the form, or dismiss the keyboard, or submit the form?
Hiding the keyboard when background is hit
I mostly agree with you here, though there are a few cases where this is useless. For example, adding a new phone number in the contact app.
Using Touch Up Inside to fire a button action
This one I really don't get. I can only guess that it's designed to allow you to use buttons instead of the touchesBegan/Moved/Ended methods. I guess it could be useful, but I've never used anything but Touch Up Inside.
Supporting the screen rotation
Many apps just don't work in any other orientation, such as games. If you want to use rotation, you only have to add two lines of code assuming you've done your layout well.
I hope this helps explain some of the strangeness. Aside from the keyboard dismissal, I've never really found anything too annoying. The one thing I wish they supported was using the highlight state of UIButtons for the set state. It would be a quick and easy toggle button, but I've taken to screenshotting a highlighted button and using that for the background image of a selected button.
Want a rounded rectangular button that isn't white? Since that one uses a background image, you can't just click something somewhere that makes it the color of your choice. You have to create your own image or you could even use CSS (WTF!?) to do it.
Unfortunately, the iPhone SDK lacks a lot of helpful things one would think would just be there. However, many people have taken the time to write wrappers for many of these kinds of things to help facilitate development - a quick google search into the functionality you are expecting may turn up a lot of useful answers!
For example, you could make the keyboard go away when you tap outside of it by creating a new view when it appears, and placing that view behind any user-interactable views on the screen. When that new view is tapped, it will become first responder and cause the keyboard to slide away (because the UITextField is no longer first responder).
Such a thing could be easily implemented as a drop-in fix for pretty much anything you'd need it for with very little code.
Still should have been included in the SDK in the first place, though!

UIPicker didSelectRow Strange Behavior

I have a 3 component dependent picker and I had it working fine until I noticed a strange behavior. If I spin component 1 and then click down with mounse on Conmponent 2, then wait for Component 1 to stop spinning then let the mouse button up, all without moving the mouse or picker wheel at all... didSelectRow does not get called at all!!! Has anyone else seen this behavior and found a work around???
Thanks
Users will use fingers and not mouse :)
You should prefer testing these kinda things on device..
Have you already seen What happens on the device?
It looks like
pickerView:didSelectRow:inComponent:
only gets called once regardless of how many components there are. Seems missleading to me but if you're spinning more than one component, you'll have to cycle through them, calling
pickerView selectedRowInComponent:
for each, regardless of which component gets passed to the method.