 |
 |
|
 |
06-20-2009, 10:02 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Posts: 175
|
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?
|
|
|
06-21-2009, 12:46 PM
|
#2 (permalink)
|
|
FasterThanMonkeys.com
iPhone Dev SDK Supporter
Join Date: Mar 2009
Location: Southern California
Posts: 517
|
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];
|
|
|
06-21-2009, 03:51 PM
|
#3 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,449
|
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
__________________
|
|
|
06-22-2009, 08:28 AM
|
#4 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Posts: 175
|
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?
|
|
|
09-01-2009, 01:59 AM
|
#5 (permalink)
|
|
Registered Member
Join Date: Apr 2008
Location: Houston, Texas
Posts: 8
|
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;
|
|
|
11-19-2009, 09:10 AM
|
#6 (permalink)
|
|
Tutorial Author
Join Date: Feb 2009
Posts: 67
|
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
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 493 |
| 49 members and 444 guests |
| Abdel, ackpth, activ8, AjohnB, Alchemda, BostonMerlin, BrianSlick, Centurion Games, ChrisMayer, CoolApps, Corey, dbarrett, dda, designomatt, dmf1978, eatenbyrats, Gamer211, gonk, greenuns, Gudus, imsatasia, IphoneSdk, jharrah, Kalimba, Knertified, LemonMeringue, Link, markbuchanan, MiniRobinho, montage, msudan, naomipunkclan, NeilB, nibby, Noise, P2k, pashik, saul102, simpsonaty, Snappy, StefanL, svguerin3, Tambourin, the1nz4ne, treazer, TunaNugget, Tuszy, victorsk, ZunePod |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,510
Threads: 35,793
Posts: 156,804
Top Poster: smasher (2,449)
|
| Welcome to our newest member, dmf1978 |
|