Created
January 28, 2012 05:20
-
-
Save kyleturner/1692818 to your computer and use it in GitHub Desktop.
When app launches, creating red light imageView, and setting up layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The application launches. Then... | |
// This creates the red light view, sets its initial opacity to 75%, and adds to window. | |
_redLightView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"RedLight"]] autorelease]; | |
_redLightView.layer.opacity = 0.75; | |
_redLightView.frame = CGRectMake(0, 170, 235, 417); | |
_redLightView.backgroundColor = [UIColor clearColor]; | |
[self.window addSubview:_redLightView]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This is the view animation block that gets executed once the red light view has been added to the window. | |
* | |
* It animates for for 2.5 seconds, and once completed displays the categories view. | |
* | |
* You'll notice I wait 0.25 seconds to call startBlueAnimation; | |
* this allows the red light to begin animating for a small instance before the blue light begins. | |
* | |
*/ | |
[UIView animateWithDuration:2.5 | |
delay: 2.0 | |
options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveLinear | |
animations:^{ | |
[self startRedAnimation]; | |
[self performSelector:@selector(startBlueAnimation) withObject:nil afterDelay:0.25]; | |
} | |
completion:^(BOOL finished){ | |
if (finished == YES) { | |
[self displayCategories]; | |
} | |
}]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This creates the red animation. | |
* It's an "opacity" animation, rotating the opacity from 0.75 to 0.1 | |
* with a duration of 0.35 seconds. | |
* | |
* It autoreverses, meaning it goes from 0.75 -> 0.1, and then reverses; 0.1 -> 0.75. | |
* Repeat count = 25, meaning it will perform the defined animation 25 times within the duration. | |
* If I didn't include autoreverse, it would ALWAYS perform 0.75 -> 0.1, 0.75 -> 0.1 (making it look skippy) | |
* | |
*/ | |
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; | |
[animation setFromValue:[NSNumber numberWithFloat:0.75]]; | |
[animation setToValue:[NSNumber numberWithFloat:0.1]]; | |
[animation setDuration:0.35]; | |
[animation setTimingFunction:[CAMediaTimingFunction | |
functionWithName:kCAMediaTimingFunctionLinear]]; | |
[animation setAutoreverses:YES]; | |
[animation setRepeatCount:25]; | |
[[_redLightView layer] addAnimation:animation forKey:@"opacity"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This creates the blue light view, sets its initial opacity to 75%, and adds to window. | |
_blueLightView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BlueLight"]] autorelease]; | |
_blueLightView.layer.opacity = 0.75; | |
_blueLightView.frame = CGRectMake(100, 170, 235, 417); | |
_blueLightView.backgroundColor = [UIColor clearColor]; | |
[self.window addSubview:_blueLightView]; | |
/* | |
* This creates the blue animation. | |
* It's an "opacity" animation, rotating the opacity from 0.75 to 0.1 | |
* with a duration of 0.35 seconds. | |
* | |
* It autoreverses, meaning it goes from 0.75 -> 0.1, and then reverses; 0.1 -> 0.75. | |
* Repeat count = 25, meaning it will perform the defined animation 25 times within the duration. | |
* If I didn't include autoreverse, it would ALWAYS perform 0.75 -> 0.1, 0.75 -> 0.1 (making it look skippy) | |
* | |
*/ | |
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; | |
[animation setFromValue:[NSNumber numberWithFloat:0.75]]; | |
[animation setToValue:[NSNumber numberWithFloat:0.1]]; | |
[animation setDuration:0.35f]; | |
[animation setTimingFunction:[CAMediaTimingFunction | |
functionWithName:kCAMediaTimingFunctionLinear]]; | |
[animation setAutoreverses:YES]; | |
[animation setRepeatCount:25]; | |
[[_blueLightView layer] addAnimation:animation forKey:@"opacity"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment