English 中文(简体)
Iphone sequential animation with setAnimationDelay
原标题:

I m trying to chain animation events. The application I m coding for work has a multiple choice quiz. First you pick your multiple choice answer. The quiz view fades away. Then a label ("correct" or "incorrect") fades in and then fades out. Finally the quiz fades back in again. The events are called and handled by a main viewController. I know I can chain events with the setAnimationDelegate and setAnimationDidStopSelector but I think it ll be easier and more clear to simply use setAnimationDelay so that all animations have time to finish before the next one fires.

I made this function that exists in the class that holds the "correct" "incorrect" label.

- (void)showIncorrect:(float)duration withDelay:(float)delay{
labelView.text = @"Incorrect!";
labelView.textColor = [UIColor redColor];

[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelay:delay];
    [UIView setAnimationDuration:(duration/2)];
    self.alpha = 1.0;
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelay:(duration/2+delay)];
    [UIView setAnimationDuration:(duration/2)];
    self.alpha = 0.0;
[UIView commitAnimations];

}

Can someone tell my why the first animation block is ignored? I ve tried to nest one animation block into the other and this does not work either.

问题回答

When you animate this way, you re actually setting the relevant value immediately, and telling what s onscreen to animate to catch up to that new reality. So whatever value you set in the first animation block is being effectively ignored, because you ve overwritten the fact that alpha == 1 by the fact that alpha == 0.

For doing more complex animations, it is worth building and adding the animations using CoreAnimation. It is a little more work, but you get lots more control.

In this case, you want to use an instance of CAKeyframeAnimation. You ll probably also want to use a CABasicAnimation to animate in your new quiz view. You can use a CAAnimationGroup to make sure that multiple animations that you add are synchronized.

I ve hit similar issues, what seems to happen is the iPhone is optimizing the drawing which occurs in the same function.

What you can try doing is splitting the function up and performSelector. For example

[self performSelector:@selector(hideMessage) withObject:self afterDelay:1.0];

I ve used this a few times with good results. If you want to see an excellent write up on doing great game style effects check out the Formic example code in iPhone cool projects. Wolfgang really pushes views for very pleasing game style effects.

Google books has it, but the book overall has some really great techniques.

Heres the google book link: http://books.google.com/books?id=_9qtPLmQxf8C&pg=PA6&lpg=PA6&dq=wolfgang+ante+formic&source=bl&ots=-vxvV3oLap&sig=G0BLW1RpItws-fwmXDI3mIjje4U&hl=en&ei=tVnzSt-3MImEMpL_8OgF&sa=X&oi=book_result&ct=result&resnum=1&ved=0CAoQ6AEwAA#v=onepage&q=wolfgang%20ante%20formic&f=false

Rich





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签