Monday, February 2, 2009

Longer Spinning & Blurring v2.0

In the comments to my last post, a few things were pointed out by readers.

First and foremost was that by changing the spin duration of the picker view, when a user manually moved a component, it would take five seconds to settle into its new position. Well, that's no good.

Here's a new version that resolves that issue.

Unfortunately, as far as I could tell, there is no way to get the picker view to change the spin duration during the run. You can return conditional values in the method, but the picker view never checks for changed values after it loads. My solution is a bit of a hack, but it works. There are two picker views - a normal one, and one using the longer-spinning subclass. They use the same data source and delegate and show the same data. When one changes, the other changes as well. The user interacts with the normal one, but when the shake or press the Spin button, the short one is hidden and the long one is unhidden, then after the spin, the long one is hidden and the normal one is unhidden. The user never sees the change, but now the behavior is correct in both manual and automatic situations.

Now, one thing to note here - A single view can't be shown on the screen twice. Currently, I have two sets of the arrays holding the data, one for each picker view. I think it might be possible to use a single one by manually having the picker views reload their data when they are unhidden, but for now, this works.

The other thing that was pointed out to me in the previous comments is that UrbanSpoon doesn't actually do anything anywhere near this complex. They use images to simulate the spinning using animation. That's a fine approach, but given the memory constraints of the iPhone and the leakiness of UIImageView animation on at least some versions of the SDK, I think I would do it this way and avoid using five megs or so worth of pre-rendered animations.



10 comments:

rymac1977 said...

Hi Jeff,

Nice post. One problem I'm having when trying to do something similar is that when using views for the rows in the picker sometimes they do not display. I notice this in your project as well, but only when I lower the animation time and all other related values. Any idea what causes this?

Thanks
Ryan

rymac said...

Over on our blog I discuss a solution to the missing rows problem, check it out here

pooja said...

Hello Sir
i have seen ypur post where urbanspoon spin code are available but i have a problem i used your project in my application but when i press on spin button it is working but after few second it's become hang on pickerview. In your application delay time is 4.7 to stop the slot machine .but i used this it's give problem so i decrease the delay time to .25 .but i want to spin functionality for more second .so give me suggestion .how to do this this as soon as.
Thanks
Pooja Rusia

pooja said...

Hello Sir,
it's Nice post .it solved my problem for mainually selection. but i am also have a another problem i want
stop the picker's component one by one .there is any idea to do this.so plz tell me as soon as .i am waiting your reply.

Thanks&Regard
pooja Rusia
iPhone Developer

mattr said...

does anyone know how to get the selected strings to a label?

Anu said...

hii Jeff,

problem is that i want to stop picker component's one by one on button click same as in urban spoon..
plz help me out asap..

Thanks,
Anu

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

Sam said...

Will the use of scrollAnimationDuration method get my app rejected on the app store?

iAppNow said...

Thanks, great post. ignore my last one as figured it out.

CHEAPSOCCERUNIFORM said...

This highlights passion which are mostly common in everyone,we should having the interest into it.
Now it will be very cold in winter, in order to keep warm yourself, moncler company has provide jackets for you, so it is better to own moncler yourselif as soon as possible. Eeveryone love fashion clothing, polo ralph lauren is very popular all over world, that is my dream to get ralph lauren.We know Ray Ban by America soldier, all of them wear ray ban sunglasses when they walk on the road, it is fashionable for you. Most of people like to wear jeans, it is very modern when wearing true religion jeans in the street.