Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($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 08-10-2010, 04:14 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default Animating a UIButton fade in/out in a loop

Hi

I am going to end up with an array of RSS feeds, and would like a button or some such to display them at the bottom of the view. I would like to animate through each feed in the array.

This is what i have so far to animate, which, works for the fade, but only animates the last item of the array.

Code:
feed = [[UIButton alloc] initWithFrame:CGRectMake(0,380,320,43)];
[self.view addSubview:feed];

feed.alpha=1;

NSArray *feeds = [NSArray arrayWithObjects:[NSString stringWithFormat:@"1234567"],
[NSString stringWithFormat:@"qwerty"],[NSString stringWithFormat:@"asdfgh"],nil];

for (NSString* f in feeds){

   [feed setTitle:f forState:UIControlStateNormal];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:2.0f];
    feed.alpha=0;
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView commitAnimations];

}
Im sure its simple.

Thanks
Joe
joec is offline   Reply With Quote
Old 08-10-2010, 04:18 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Code:
feed = [[UIButton alloc] initWithFrame:CGRectMake(0,380,320,43)];
[self.view addSubview:feed];

feed.alpha=1;

NSArray *feeds = [NSArray arrayWithObjects:[NSString stringWithFormat:@"1234567"],
[NSString stringWithFormat:@"qwerty"],[NSString stringWithFormat:@"asdfgh"],nil];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2.0f];
for (NSString* f in feeds){
   [feed setTitle:f forState:UIControlStateNormal];
   feed.alpha=0;
}    
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
Try this.
TUX2K is offline   Reply With Quote
Old 08-10-2010, 04:25 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

Thanks, I tried that, and it still seems to just animate the last item. Would i need an NSTimer as well?
joec is offline   Reply With Quote
Old 08-10-2010, 04:28 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

It also looks like you just have one button called feed.
What you could do is in the animationDidStop set the next label via animantion.
And repeat until done.

This way you will not need a timer.
TUX2K is offline   Reply With Quote
Old 08-10-2010, 04:33 AM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

I do have only one button called feed, i essentially just want to replace the title of the button, after fading the previous one out...

My animationDidStop method just looks like:
Code:
	[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2.0f];
	feed.alpha = 0;
	[UIView commitAnimations];
What would i need to change in this?

Thanks.
joec is offline   Reply With Quote
Old 08-10-2010, 04:41 AM   #6 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Create a property for feeds array and a property with the current index.

Start with position 0 in your first call and set the current index to 0 and start the first animation

Then in the animation did stop, check if the current index is large then the count of the array.
If not up the curentindex with one and do the animation again.
TUX2K is offline   Reply With Quote
Old 08-10-2010, 04:56 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

I have done this now, and it animates the first item twice now :s

Code:
	if (!(currentIndex > [appDelegate.feeds count])) {
		[UIView beginAnimations:nil context:NULL];
		[UIView setAnimationCurve:UIViewAnimationOptionCurveEaseIn];
		[UIView setAnimationDuration:2.0f];
		[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

		Feed *f = [appDelegate.feeds objectAtIndex:currentIndex];
		[feed setTitle:f.author forState:UIControlStateNormal];
		[feed addTarget:self action:@selector(popUpModal:) forControlEvents:UIControlEventTouchUpInside];
		feed.alpha=1;
		
		[UIView commitAnimations];
		currentIndex++;
	}

What have i missed? It's very early here
joec is offline   Reply With Quote
Old 08-10-2010, 05:03 AM   #8 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Looks correct to me.
TUX2K is offline   Reply With Quote
Old 08-10-2010, 05:04 AM   #9 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

Should it be an if or while?
joec is offline   Reply With Quote
Old 08-10-2010, 05:32 AM   #10 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

If should be just fine, because you call the function every time the animation is stopped.
TUX2K is offline   Reply With Quote
Old 08-10-2010, 05:36 AM   #11 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

I understand that it should work, but it is behaving weirdly... I've never done animation before, so i am possibly missing something, either in the initial animation call or the didStop method... where do i set currentIndex to 0, before or after the initial animation ?
Thanks
joec is offline   Reply With Quote
Old 08-10-2010, 05:41 AM   #12 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

OK, so now i have got it Looping through them all, but it still does the first one twice i assume because in the first call when the index is 0, its still matching the if condition...
joec is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, fade, loop, uiview

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
» Online Users: 324
9 members and 315 guests
flamingliquid, ilmman, iram91419, linkmx, nadav@webtview.com, Objective Zero, Paul Slocum, stanny, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,656
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, iram91419
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:41 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0