Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

happybob

macrumors newbie
Original poster
Apr 18, 2009
17
0
Hi All, I'm trying to transform shift a series of buttons at the same time named: pos1, pos2, etc.

I can do the transformation easily:

pos1.transform = CGAffineTransform....

Is there a way to create an array or some other structure so that I only need a single instance of the transform:

allbutton.transform = CGAffineTransform....

Thanks
 
Hi All, I'm trying to transform shift a series of buttons at the same time named: pos1, pos2, etc.

I can do the transformation easily:

pos1.transform = CGAffineTransform....

Is there a way to create an array or some other structure so that I only need a single instance of the transform:

allbutton.transform = CGAffineTransform....

Thanks

well, you could add all the objects to an array and then do something like:
Code:
for (UIButton *button in myArray) {
  button.transform = ...;
}
this would go through all "UIButton" objects in the array myArray
 
Hi All, I'm trying to transform shift a series of buttons at the same time named: pos1, pos2, etc
Are you just moving the buttons (i.e. changing their origins) within the view? If so, you don't really need to use CGAffineTransform. You can just adjust their frames.
 
Thanks again BlackWolf. The only problem, which I forgot to mention, is that I need to be able to change which objects move. This is what I have:

int divide_int = 6 //All pos#'s under this are moved

NSArray *posmove = [[NSArray alloc] arrayWithObjects: pos1, pos2, pos3, etc, nil];

for ( i = divide_int, i <= number_of_objects_in_array, i++ ) {
posmove.transform = CGAffineTransform
}

Anyway to make this work?

Dejo: I'm also hiding the buttons that don't move which I can place into a similar setup once I get this working. Thanks, for the idea though.

What I also want to do is, but sadly it doesn't work.

posmove.hidden = YES;
 
Thanks again BlackWolf. The only problem, which I forgot to mention, is that I need to be able to change which objects move. This is what I have:

int divide_int = 6 //All pos#'s under this are moved

NSArray *posmove = [[NSArray alloc] arrayWithObjects: pos1, pos2, pos3, etc, nil];

for ( i = divide_int, i <= number_of_objects_in_array, i++ ) {
posmove.transform = CGAffineTransform
}

Anyway to make this work?

Dejo: I'm also hiding the buttons that don't move which I can place into a similar setup once I get this working. Thanks, for the idea though.


actually, there are several ways.
you could do pretty much what you posted. look at NSArray's documentation and you will see that it has a "count" property which gives you the total number of elements in the array. and you can access a specific element via NSArray's objectAtIndex: method.

second posibility would be to take the code I posted, and simply add an index that you set to 0 before the loop and increase it inside the loop. inside the loop you check if the index is bigger than divide_int and if so, perform your transformation.

but in your case the first solution would probably be better.
 
What I also want to do is, but sadly it doesn't work.

posmove.hidden = YES;

posmove is an NSArray, right? So, what you'll want to do is:

Code:
[posmove objectAtIndex:i].hidden = YES;
or
Code:
[[posmove objectAtIndex:i] setHidden:YES];

P.S. Please use the CODE tags to include your code. Makes it easier for us all to read.
 
Sorry but when I try those and then launch the simulator locks up. What I have done:

Code:
for ( i = divide_int, i <= 8, i++ ) {
((UIButton *)[posmove objectAtIndex:i]).transform = CGAffineTransform...;
[posmove objectAtIndex:i].hidden = NO;
}

Also when I try exactly what you had dejo, it comes up with an error: "request for member 'hidden' in something not a structure or union"

The Array is written like this:

Code:
NSArray *posmove = [[NSArray alloc] arrayWithObjects: pos1, pos2, pos3, pos4, etc, nil];

Sorry I'm not getting this
 
yeah, same thing happened to me when it comes to hidden. you should use setHidden:something
worked for me.

also, I think [something].somethingElse does not work. use [[something] setSomethingElse:value]

also, did you properly initialize your i variable as ain int?

AND you should look at the syntax of a for loop. it uses ; as seperators, not ,

seems to me like you should really go over the basics again!
 
Thanks. Everyone my problem with the errors was that I stupidly forgot that 0 is a number in the array.
 
Also when I try exactly what you had dejo, it comes up with an error: "request for member 'hidden' in something not a structure or union"

The Array is written like this:

Code:
NSArray *posmove = [[NSArray alloc] arrayWithObjects: pos1, pos2, pos3, pos4, etc, nil];

Sorry I'm not getting this
What class is pos1, pos2, etc.?

Also, you either wanna:
Code:
NSArray *posmove = [[NSArray alloc] initWithObjects: pos1, pos2, pos3, pos4, etc, nil];
or
Code:
NSArray *posmove = [NSArray arrayWithObjects: pos1, pos2, pos3, pos4, etc, nil];
 
What class is pos1, pos2, etc.?

Also, you either wanna:
Code:
NSArray *posmove = [[NSArray alloc] initWithObjects: pos1, pos2, pos3, pos4, etc, nil];
or
Code:
NSArray *posmove = [NSArray arrayWithObjects: pos1, pos2, pos3, pos4, etc, nil];

lol, I didn't even notice that :D
@OP: make sure you know what convenience constructors (like arrayWithObjects:) do, that's really important!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.