help me about buttons

Discussion in 'iOS Programming' started by electronica, Sep 24, 2011.

  1. electronica macrumors newbie

    Joined:
    Sep 24, 2011
    #1
    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.
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    You can get the button with a particular tag by sending viewWithTag: to the super-view common to all the buttons.
     
  3. electronica, Sep 24, 2011
    Last edited by a moderator: Sep 24, 2011

    electronica thread starter macrumors newbie

    Joined:
    Sep 24, 2011
    #3
    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?
     
  4. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    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.
     
  5. electronica thread starter macrumors newbie

    Joined:
    Sep 24, 2011
    #5
    i get it, thank you very much for your kind replies.
     
  6. electronica, Sep 24, 2011
    Last edited by a moderator: Sep 24, 2011

    electronica thread starter macrumors newbie

    Joined:
    Sep 24, 2011
    #6
    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?
     
  7. electronica, Sep 24, 2011
    Last edited by a moderator: Sep 24, 2011

    electronica thread starter macrumors newbie

    Joined:
    Sep 24, 2011
    #7
    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.
     
  8. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #8
    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.
     
  9. electronica thread starter macrumors newbie

    Joined:
    Sep 24, 2011
    #9
    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.
     
  10. electronica thread starter macrumors newbie

    Joined:
    Sep 24, 2011
    #10
    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?
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    UIImageView is a subclass of UIView. So, what's good for the super is (usually) good for the sub, so to speak.
     
  12. electronica, Sep 28, 2011
    Last edited by a moderator: Sep 28, 2011

    electronica thread starter macrumors newbie

    Joined:
    Sep 24, 2011
    #12
    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?
     
  13. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #13
    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:
    So this isn't going to get you what you want.
     
  14. electronica thread starter macrumors newbie

    Joined:
    Sep 24, 2011
    #14
    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 :(
     

Share This Page