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

electronica

macrumors newbie
Original poster
Sep 24, 2011
17
0
hi there, im new to this forum so dont get mad to me if is there any mistakes.

shortly what i need is:
i want to transform and scale a button which tag is 1.

i have 9 buttons in my view. and when touched to the screen i want to move and scale these buttons with different amount. so i need to reach the button which tag is 1,2,, etc.
i can get a button's tag but cant get a tag's button.

any tips will be very helpful and sorry for my crappy english.
thank you.
 
You can get the button with a particular tag by sending viewWithTag: to the super-view common to all the buttons.
 
thank you for the fast reply, this really helped me. so my code is:

Code:
CGAffineTransform ileri = CGAffineTransformMakeTranslation(170, 0);
[self.view viewWithTag:1].transform = ileri;

so this code search the views and get the first view it finds which tag is 1.
but i have 9 other small views other than buttons. so these views also have the same tags with buttons. how can i change this code so it looks only for buttons not all views?

or changing the tags to different value is the only way?
 
Last edited by a moderator:
thank you for the fast reply, this really helped me. so my code is:

CGAffineTransform ileri = CGAffineTransformMakeTranslation(170, 0);
[self.view viewWithTag:1].transform = ileri;

so this code search the views and get the first view it finds which tag is 1.
but i have 9 other small views other than buttons. so these views also have the same tags with buttons. how can i change this code so it looks only for buttons not all views?

or changing the tags to different value is the only way?

Tags in a view hierarchy are meant to unique, so changing the tags of the buttons to more unique values is probably the easiest way forward.

If you're using the tags in other meaningful ways, add some constant value to them, say 1000, then you can still use their tags values meaningfully by simply subtracting that constant.
 
hi again, i need help with another issue, if you dont mind.
Code:
-(void)ileri:(id)sender
{

    CGAffineTransform ileri = CGAffineTransformMakeTranslation(170, 0);
    CGAffineTransform ileri2 = CGAffineTransformMakeTranslation(682, 0);
    CGAffineTransform buyut = CGAffineTransformMakeScale(2, 2);
    CGAffineTransform kucult = CGAffineTransformMakeScale(0.5, 0.5);
    CGAffineTransform ileribuyut = CGAffineTransformConcat(ileri, buyut);
    CGAffineTransform ilerikucult = CGAffineTransformConcat(ileri2, kucult);
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];

    [self.view viewWithTag:1].transform = ileribuyut;
    [self.view viewWithTag:2].transform = ilerikucult;
    
    [UIView commitAnimations];

}

when i click my button, this method is called. but when i click the button second time, the animation will not work again. what im missing?
 
Last edited by a moderator:
well i realized something. it seems the problem is the CGaffinetransform methods which im using wrong.

when i use
Code:
[self.view viewWithTag:1].transform = ileribuyut;
it is okay for the first time, but when i call the method second time, it takes the button's initial location not the newly translated or scaled location.

so, what i wanna do is: when i touched to screen, i want to apply the same amount of transformation and scale to the button.
 
Last edited by a moderator:
You need to fixate the animation after it completes. By fixate I mean you need to reset the model properties so that they are the same as the animated properties. Then you can apply a further set of animations.

Code:
// at top
#import <QuartzCore/QuartzCore.h>

// later

- (void)fixateView:(UIView*)view
{
    CALayer* presentationLayer = [view.layer presentationLayer];
    CGRect frame = presentationLayer.frame;
    view.transform = CGAffineTransformIdentity;
    view.frame = frame;
}

- (IBAction)ileri:(id)sender
{
    CGAffineTransform ileri = CGAffineTransformMakeTranslation(170, 0);
    CGAffineTransform ileri2 = CGAffineTransformMakeTranslation(682, 0);
    CGAffineTransform buyut = CGAffineTransformMakeScale(2, 2);
    CGAffineTransform kucult = CGAffineTransformMakeScale(0.5, 0.5);
    CGAffineTransform ileribuyut = CGAffineTransformConcat(ileri, buyut);
    CGAffineTransform ilerikucult = CGAffineTransformConcat(ileri2, kucult);

    UIView* button1 = [self.view viewWithTag:1];
    UIView* button2 = [self.view viewWithTag:2];
     
    [UIView
        animateWithDuration:0.5
        animations:
            ^{
                button1.transform = ileribuyut;
                button2.transform = ilerikucult;
            }
        completion:
            ^(BOOL finished){
                if (finished) {
                    [self fixateView:button1];
                    [self fixateView:button2];
                }
            }
        ];
}

Note that I also updated your core animation code to the use the new block technique. The old animation technique is strongly discouraged. This assumed you're okay with targeting iOS 4.
 
wow, this really worked perfectly. thank you very much agian. So i think presentationLayer.frame is my butons frame after the transformation.
anyway this helped me much.
 
okey here is the other question.

how can i change the image of a imageview with a standart animations. i have only 1 imageview and what i need is to change the image with flip animation.

i know how to do it with when changing from uiview to uiview with settransationmodelstyle kind of stuff. but im stuck with this.

any help?
 
ok, but i cant figure it out how to do it.

my code is like this, so with "ileri" method i change the image with the next one in array.
Code:
-(IBAction)ileri{
    if (deger < [resimarray count]-1) {
		deger++; 
     }   
    imageview.image = [UIImage imageNamed:[resimarray objectAtIndex:deger]];
}

when i try to set a transitionstyle to imageview like below, it says it wont respond.

[imageview setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];

can you please correct me?
 
Last edited by a moderator:
After searching for modalTransitionStyle in the docs, I find only one class that has this method. It's UIViewController. UIImageView doesn't inherit from UIViewController, so UIImageView doesn't have this method.

Also from the docs for modalTransitionStyle:
The transition style to use when presenting the current view controller modally.

This property affects the way the current view controller is presented when it is presented using the presentModalViewController:animated: method.

So this isn't going to get you what you want.
 
ohh i see,

than maybe i should try to use 2 different views with a viewcontroller and everytime with the method i will change one to another with a different image.

i dont know how to handle this, and because my images change instantly it seems so bad :(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.