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 09-01-2011, 02:12 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 16
Falimond is on a distinguished road
Default How to get a method to act on different parameters?

Hello All,

I've got a method (IBAction)toggleState which is triggered by a custom button that sits atop a square image. The image is a representation of the button and can either be black or white. When the button is pressed an animation of that button flipping over can be seen. I have this working perfectly, with one button.

Now I need to implement an array of 6x8 button images each with its own custom button where a button tap will animate the corresponding button image as well as any surrounding button images of my choosing. All the button states must be saved and updated after each method call.

Here's what I have for a single button implementation. The button image starts off white and with a state of -1.



*Problem solved...thanks!

Last edited by Falimond; 09-01-2011 at 06:55 PM. Reason: Clarification
Falimond is offline   Reply With Quote
Old 09-01-2011, 10:26 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 16
Falimond is on a distinguished road
Default

*bump*
Falimond is offline   Reply With Quote
Old 09-01-2011, 10:47 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 280
dapis is on a distinguished road
Default

Quote:
Originally Posted by Falimond View Post
Hello All,

I've got a method (IBAction)toggleState which is triggered by a custom button that sits atop a square image. The image is a representation of the button and can either be black or white. When the button is pressed an animation of that button flipping over can be seen. I have this working perfectly, with one button.

Now I need to implement an array of 6x8 button images each with its own custom button where a button tap will animate the corresponding button image as well as any surrounding button images of my choosing. All the button states must be saved and updated after each method call.

Here's what I have for a single button implementation. The button image starts off white and with a state of -1.

Code:
int i = -1;

-(IBAction)toggleState:(id)sender 
{

switch(i){

      case 1:       {
NSArray *flip_to_white = [[NSArray alloc] initWithObjects:
			[UIImage imageNamed:@"flip_black_1.png"],
			.
			.
			.
		       [UIImage imageNamed:@"flip_white_1.png"],     // item 58 - white button image
			nil  ];
			        
	buttonImage.animationImages = flip_to_white;
	buttonImage.animationDuration = .3;
	buttonImage.animationRepeatCount = 1;
	buttonImage.image = [flip_to_white objectAtIndex: 58];
	[buttonImage startAnimating];
			
		i = (i*-1);
		break;
		       }
		
     case -1:       {
NSArray *flip_to_black = [[NSArray alloc] initWithObjects:
		        [UIImage imageNamed:@"flip_white_1.png"],
			.
			.
			.
		       [UIImage imageNamed:@"flip_black_1.png"],     // item 58 - black button image
		        nil  ];
			        
		buttonImage.animationImages = flip_to_black;
		buttonImage.animationDuration = .3;
		buttonImage.animationRepeatCount = 1;
		buttonImage.image = [flip_to_black objectAtIndex: 58];
		[buttonImage startAnimating];
		i = (i*-1);
		break;
		         }
            }

}

I've given up solving it on my own :/ I have experience with C but only started iPhone dev. this week. I could define a different method for each button and control other button images in each of those methods... but there has to be a simpler way.
You can deal with the same code for multiple images by naming the images in numerical order such as myImage1.png, myImage2.png, etc.

Then use something akin to the following - where your code has provided the int k as the number of the desired image:

UIImage *theImageToUse =
imageNamed:[NSString stringWithFormat:@"myImage%d.png", k]
dapis is offline   Reply With Quote
Old 09-01-2011, 11:08 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 16
Falimond is on a distinguished road
Default

I just placed the animation arrays at the beginning of the method definition that way I can just reuse flip_to_white/black throughout the method.

To cause different images to flip I've done this.
Code:
		UIImageView *imageFlipped = image0;
		
		if(A[i] == 1)	{
			imageFlipped.animationImages = flip_to_white;
I got this working and it will cause image0 to flip. Is there a way to define imageFlipped with different images in a loop? Something along the lines of....

Code:
		
       for(i=0;i < 4;i++){
                x = A[i];
                UIImageView *imageFlipped = image<x>;

		if(A[i] == 1)	{
			imageFlipped.animationImages = flip_to_white;
                        .....            }

                                 }
Where A[i] is an array containing the image values that I want flipped.

Last edited by Falimond; 09-01-2011 at 11:35 AM.
Falimond is offline   Reply With Quote
Reply

Bookmarks

Tags
action, animation, array, button, method

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: 396
5 members and 391 guests
JackReidy, jeroenkeij, Sami Gh, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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