Hi,
I need some help with a small application I created to learn how animations work. My application consists of one UIView, one UIImageView, 2 buttons for scaling UIImageView up and down.
So the main view looks like this:
So when I touch the scale up button and hold it, the image should be scaled. And it is, but I cannot see any transition
When I touch and hold the button it looks like nothing is happening, but when I release the button, the image is instantly scaled up. It would be really cool if I could see the image getting bigger and bigger while holding the button, so can anyone tell me what am I missing or what am I doing wrong?
I need some help with a small application I created to learn how animations work. My application consists of one UIView, one UIImageView, 2 buttons for scaling UIImageView up and down.
Code:
@class AnimationsViewController;
@interface AnimationsAppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
UIView* theView;
UIImageView* theImageView;
UIButton* scaleUpButton;
UIButton* scaleDownButton;
BOOL scalingUp;
BOOL scalingDown;
}
@property (nonatomic, retain) UIWindow *window;
- (void)scaleUpButtonTouchDown;
- (void)scaleUpButtonTouchUp;
- (void)scaleDownButtonTouchDown;
- (void)scaleDownButtonTouchUp;
- (void)continueScalingUp;
- (void)continueScalingDown;
@end
Code:
- (void)scaleUpButtonTouchDown {
NSLog(@"scale up button touch down");
NSLog(@"ustawiam scalingUp na 1");
scalingUp = YES;
[NSThread detachNewThreadSelector:@selector(continueScalingUp) toTarget:self withObject:nil];
}
- (void)continueScalingUp {
NSAutoreleasePool * thePool = [[NSAutoreleasePool alloc] init];
NSLog(@"continue scaling up");
while(scalingUp) {
[UIView beginAnimations:nil context:nil];
if(scale<5.03) {
scale+=.01;
}
NSLog(@"scale up multiplier = %f",scale);
[UIView setAnimationDuration:.15];
CGAffineTransform transform = CGAffineTransformMakeScale(scale,scale);
theImageView.transform = transform;
[UIView commitAnimations];
}
[thePool release];
}
- (void)scaleUpButtonTouchUp {
NSLog(@"scale up button touch up inside");
NSLog(@"ustawiam scalingUp na 0");
scalingUp = NO;
}
- (void)scaleDownButtonTouchDown {
NSLog(@"scale down button touch down");
scalingDown = YES;
[NSThread detachNewThreadSelector:@selector(continueScalingDown) toTarget:self withObject:nil];
}
- (void)continueScalingDown {
NSAutoreleasePool * thePool = [[NSAutoreleasePool alloc] init];
NSLog(@"continue scaling down");
while(scalingDown) {
[UIView beginAnimations:nil context:nil];
if(scale>.02) {
scale-=.01;
}
NSLog(@"scale down multiplier = %f",scale);
[UIView setAnimationDuration:.15];
CGAffineTransform transform = CGAffineTransformMakeScale(scale,scale);
theImageView.transform = transform;
[UIView commitAnimations];
}
[thePool release];
}
- (void)scaleDownButtonTouchUp {
NSLog(@"scale down button touch up inside");
scalingDown = NO;
}
So the main view looks like this:
So when I touch the scale up button and hold it, the image should be scaled. And it is, but I cannot see any transition
Last edited by a moderator: