Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone ($4.99)

dotnetIQ ($4.99)

Your First iPhone App ($1.99)

iPocket Tools 9 in 1 ($0.99)

Catch-Me (Free)

Alien Strike ($0.99)

Historic Olympic Medal-Table ($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-20-2009, 10:02 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 175
Default setAnimationDuration... its just not happening...

hello all

i am trying fade a view in and out... which is simple in concept... but for some reason my code fires instantaneously rather than taken the specified amount of time to animate the transition. here is my code

Code:
- (void) fadeIn {
	[[self myView] setAlpha:0.0];
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:2.0f];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
	[UIView setAnimationBeginsFromCurrentState:YES];
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(fadeOut)];
	
	[[self myView] setAlpha:0.8];
	
	[UIView commitAnimations];
}

- (void) fadeOut {
	NSLog(@"fadeOut called"); // just a marker so i can see if this is being called after 2 seconds
}
my problem is when fadeIn is called, the alpha is immediately set to 0.8 and fadeOut is called (i can see the nslog statement pop up as soon as i see the view)

any idea's as to why this is happening?
__________________
-- Current Apps --
Musicopoulos
gabacus is offline   Reply With Quote
Old 06-21-2009, 12:46 PM   #2 (permalink)
ftm
FasterThanMonkeys.com
iPhone Dev SDK Supporter
 
Join Date: Mar 2009
Location: Southern California
Posts: 517
Send a message via AIM to ftm
Default

When setting the alpha, try using:

Code:
myView.alpha = 0.0;
and

Code:
myView.alpha = 0.8;

And you should not need this line at all:

Code:
[UIView setAnimationBeginsFromCurrentState:YES];
__________________


Website: http://fasterthanmonkeys.com

iScore Baseball Scorekeeper Top baseball scorekeeping app for iPhone
Bug Squash Reached #1 kids game in 15+ countries including USA, now with OpenFeint
Jam Packed! Fun puzzle game for all ages
Jam Packed Christmas Holiday puzzle game!
iScore Basketball Scorekeeper Best basketball scorekeeping application
ftm is offline   Reply With Quote
Old 06-21-2009, 03:51 PM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,449
Default

Where are you calling "fadeIn" from? If it's in the view's init or viewDidLoad, it's probably too soon. Try it from viewWillAppear instead.

Also, your stop selector should have this signature; this shouldn't keep fadeIn from working, though.

Code:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
__________________
smasher is offline   Reply With Quote
Old 06-22-2009, 08:28 AM   #4 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 175
Default

thanks for the responses guys!

i finally got it working

i ended up calling the animation blocks from the viewDidLoad method and it is now working the way i want it too. im not sure why it was causing problems though... where can i read up more on this?

smasher, i have not seen the animationDidStop method before and im not really sure how to use it...

[UIView setAnimationDidStopSelector:@selector(fadeOut)];

seems to be working fine for me. is it likely to cause problems? what is the difference between the 2 methods?
__________________
-- Current Apps --
Musicopoulos
gabacus is offline   Reply With Quote
Old 09-01-2009, 01:59 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Houston, Texas
Posts: 8
Default

The trick is you need to setAnimationDuration: (and all the other animation values) before you setAlpha:.
The behind-the-scenes animation setup gets created when you set the value being animated.

Also, what smasher was saying about the setAnimationDidStopSelector: is that UIView assumes a method signature identical to

Code:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
which is to say you could call it:
Code:
- (void)x:(NSString *)id y:(NSNumber *)boolNumber z:(void *)nothing;
and still be in good programming style,

you obviously aren't using any of the parameters, so your callback will work,
the additional parameters are pushed onto the stack and ignored,

not guaranteed safe in all architectures of Objective-C, but okay on Intel and iPhone processors,

I would suggest something like:
Code:
[UIView setAnimationDidStopSelector:@selector(fadeInDidStop:finished:context:)];

- (void)fadeInDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
bshirley is offline   Reply With Quote
Old 11-19-2009, 09:10 AM   #6 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 67
Default

i would also like to say something i have discovered

the uiview animation expects something that is tangible inside of the animation block

i noticed that on some operations that are not interpolative, it doesnt work, ie, i can specify 6.0 seconds for the delay, and inside of the block, do something that does not interpolate from 0 to a value, it doesnt wait the 6.0 seconds, it skips straight to the finished method you specified.

correct me if i am wrong
mr tickle is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 21,510
Threads: 35,793
Posts: 156,804
Top Poster: smasher (2,449)
Welcome to our newest member, dmf1978
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:47 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0