views:

62

answers:

2

Hi,

I have a application that runs a timer and performs a action 30 times a second. What I want to do is change the size of a UIButton i have so that every time the timer goes around, it changes the UIButton so that it is a little bit smaller. I have played with a bunch of things I have found online and I still cant figure it out.

Any ideas?

A: 

Try something like:

CGRect tempFrame = myButton.frame;    
myButton.frame = CGRectInset(tempFrame,5,5);
jenningj
+1  A: 

So, to move the comment out - is this generally what you're trying to do?

-(void) calledWhenTimerGoesRound
{
    NSLog(@"calledWhenTimerGoesRound"); 
    [UIView beginAnimations:nil context:@"MyAnimation"]; 

    CGRect tempFrame = myButton.frame; 
    tempFrame.size.width = tempFrame.size.width - 5.0f; 
    tempFrame.size.height = tempFrame.size.height - 5.0f; 
    myButton.frame = tempFrame;

    [UIView commitAnimations];
}

What does your timer code look like? Here's and example of what should work (resize the button smaller every second):

- (void) startMyTimer
{
    NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(calledWhenTimerGoesRound) userInfo:nil repeats:YES];

    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
Eric
Yes, I thought that that would maybe make the button smaller every time the timer goes around, but it doesn’t.
Have you checked using Xcode's debugger that `myButton` is not `nil`?
jrtc27
Its not, i use myButton to do other things such as move the button around the screen as the timer goes around and it works fine.