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开发者_StackOverflow社区 a bunch of things I have found online and I still cant figure it out.
Any ideas?
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];
}
Try something like:
CGRect tempFrame = myButton.frame;
myButton.frame = CGRectInset(tempFrame,5,5);
精彩评论