Hi there everyone. I've managed to set up a button which when pressed displays a thought bubble. The bubble appears first as a smaller bubble, then a slightly larger bubble, then finally the full sized bubble, all in quick succession. I've managed to do this just fine with the following code, I'm just wondering if this really is the best way to do it? If I wanted to add more smaller bubbles, I'd be adding more methods, which doesn't really seem optimal. I guess I'm asking if there's a way it can all be done in a single method call, i.e. call a delay on each line without having to create a new method. Here's my code:
- (void)showThoughtBubble {
bubble1.hidden = FALSE;
[self performSelector:@selector(showBubble2) withObject:nil afterDelay:0.3];
}
- (void)showBubble2 {
bubble2.hidden = FALSE;
[self performSelector:@selector(showBubble3) withObject:nil afterDelay:0.3];
}
- (void)showBubble3 {
thoughtBubble.hidden = FALSE;
}
- (void)hideThoughtBubble {
bubble1.hidden = TRUE;
bubble2.hidden = TRUE;
thoughtBubble.hidden = TRUE;
}
- (IBAction)thoughtButtonPressed {
if (thoughtBubble.hidden)
[self showThoughtBubble];
else
[self hideThoughtBubble];
}
Along the same lines, I've written the following code in order to make a static character I have on screen, blink every now and then. I'm curious to see if anyone would suggest a different approach, as I may be adding more animations to this one character, and I'm not sure adding multiple timers and method calls is the best way?
- (void)startBlinkCycle {
NSLog(@"Starting cycle");
[blinkTimer invalidate];
NSRunLoop *myRunLoop = [NSRunLoop currentRunLoop];
NSDate *now = [[NSDate alloc]init];
blinkTimer = [[NSTimer alloc]
initWithFireDate:now
interval:5
target:self
selector:@selector(blink:)
userInfo:nil
repeats:YES];
[now release];
[myRunLoop addTimer:blinkTimer forMode:NSDefaultRunLoopMode];
[blinkTimer release];
}
- (void)blink:(NSTimer *)theTimer {
[self.mainImageView setImage:blinkImage];
[self performSelector:@selector(unblink) withObject:nil afterDelay:0.2];
}
- (void)unblink {
[self.mainImageView setImage:mainImage];
}