CGAffineTransformMakeTranslation and UIButton's titleLabel

Discussion in 'iOS Programming' started by dantastic, May 2, 2014.

  1. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #1
    I am working on a UIButton subclass. at one point I want to show an activity indicator inside the button. I'm thinking I'd just animage the titleLabel over to the side a small bit like so:

    (this is inside a UIButton subclass)
    Code:
    	[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    		self.titleLabel.transform = CGAffineTransformMakeTranslation(30, 0);
    	} completion:nil];
    
    The title label animates over to where it should be - but then it animates back!
    However, if we so something like
    Code:
    	[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    		self.titleLabel.transform = CGAffineTransformMakeRotation(0.4);
    	} completion:nil];
    the label animates to where it should be and it stays there.

    If I apply the above translation code to any other object, say, the button itself!
    Code:
    - (IBAction)buttonPressed:(id)sender {
    	
    	[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    		self.button.transform = CGAffineTransformMakeTranslation(-30, 10);
    	} completion:^(BOOL finished) {
    		
    	}];
    }
    I get a more expected result tho. Is there something funny going on with UIButton subviews or am I missing something obvious?
     
  2. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    Is it possible that in the drawRect for uibuttons it removes the label and re-draws it?

    edit: just realized that might not make sense because you said the rotation stays put
     

Share This Page