I have an error in my code that i cannot fix..
here is my code.. it is inside the first if statement where current_region++ occurs... please help me, thank you
-(void)planetRotation:(UIView *)planet average:(float )time1 perihelion:(float )time2 aphelion:(float )time3 region:(int ) current_region
{
current_region = 0;
[planet.layer removeAllAnimations];
if (current_region == 0 || current_region == 2)
{
[UIView animateWithDuration:time1 delay:0.0 options: UIViewAnimationOptionTransitionNone
animations: ^{ CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * time1 * 1 ];//multiply more to add speed
rotationAnimation.duration = time1/4;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = HUGE_VALF;
[planet.layer addAnimation:rotationAnimation forKey:@"orbit"];} completion:^(BOOL finished){current_region++; }];
}
else if(current_region == 1)
{
[UIView animateWithDuration:time2 delay:0.0 options: UIViewAnimationOptionTransitionNone
animations:^{ CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * time2 * 1 ];//multiply more to add speed
rotationAnimation.duration = 15;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = HUGE_VALF;
[planet.layer addAnimation:rotationAnimation forKey:@"orbit"];} completion:^(BOOL finished){ }];
}
else if(current_region == 3)
{
[UIView animateWithDuration:time3 delay:0.0 options: UIViewAnimationOptionTransitionNone
animations:^{ CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * time3 * 1 ];//multiply more to add speed
rotationAnimation.duration = 15;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = HUGE_VALF;
[planet.layer addAnimation:rotationAnimation forKey:@"orbit"];} completion:^(BOOL finished){ }];
}
When you declare your current_region variable you need to modify the declaration like this:
__block int current_region = 0;
Apple says:
__block variables live in storage that is shared between the lexical scope of the variable and all blocks and block copies declared or created within the variable’s lexical scope. Thus, the storage will survive the destruction of the stack frame if any copies of the blocks declared within the frame survive beyond the end of the frame (for example, by being enqueued somewhere for later execution). Multiple blocks in a given lexical scope can simultaneously use a shared variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With