Created
March 17, 2010 23:36
-
-
Save cqa02303/335863 to your computer and use it in GitHub Desktop.
This file contains 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
#pragma mark - | |
#pragma mark animationScenario | |
// イメージを横長の領域に散らして配置したViewを作成する | |
- (id)initWithImages:(NSArray*)images { | |
if (self = [super init]) { | |
// Initialization code | |
NSLog(@"EasterEggImage initWithImage"); | |
int randVal = 0; | |
UIImageView *timage = nil; | |
id orgImage = nil; | |
int placedelay = stageWidth / gadgets; | |
timage = [images objectAtIndex:0]; | |
int placeWidth = placedelay; | |
if (timage != nil) { | |
placeWidth -= timage.bounds.size.width; | |
placeWidth = placeWidth == 0 ? 1 : placeWidth; | |
} | |
NSLog(@"placeWidth, placedelay = %d, %d", placeWidth, placedelay); | |
for (int i = 0; i < gadgets; i++) { | |
SecRandomCopyBytes(kSecRandomDefault, 4, (uint8_t*)&randVal); | |
orgImage = [images objectAtIndex:randVal % images.count]; | |
timage = [[[UIImageView alloc] initWithImage:((UIImageView*)orgImage).image] autorelease]; | |
timage.center = CGPointMake(placedelay * i + (randVal >> 16) % placeWidth, - (randVal & 0xffff) % stageHeight); | |
// NSLog(@"point %0.2f, %0.2f", timage.center.x, timage.center.y); | |
[self addSubview:timage]; | |
} | |
SecRandomCopyBytes(kSecRandomDefault, 2, (uint8_t*)&randVal); | |
self.alpha = 0.0f; | |
self.center = CGPointMake(0.0f, 0.0f); | |
SecRandomCopyBytes(kSecRandomDefault, 4, (uint8_t*)&randVal); | |
self.startPoint = CGPointMake((randVal >> 16) & 0x0ffff % 320, (randVal & 0x0ffff) % 480); | |
} | |
return self; | |
} | |
// ガジェットアニメーション | |
// ※継承してここを書き換える事で動作が変わります。 | |
- (void)startAnimating { | |
NSLog(@"EasterEggView -startAnimating"); | |
CGMutablePathRef thePath = CGPathCreateMutable(); | |
//Start Point | |
CGPathMoveToPoint(thePath, NULL, self.startPoint.x, self.startPoint.y); | |
CGPathAddLineToPoint(thePath, NULL, self.endPoint.x, self.endPoint.y); | |
// KeyAnimationを作成(座標) | |
CAKeyframeAnimation* positionAnimation; | |
positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; | |
positionAnimation.path = thePath; | |
positionAnimation.duration = 5.0f; | |
//描画速度の調整 | |
positionAnimation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.0f :0.0f :0.6f :0.8f]; | |
[self.layer addAnimation:positionAnimation forKey:@"imagePosition"]; | |
CFRelease(thePath); | |
} | |
#pragma mark - | |
#pragma mark CAAnimationDelegate | |
// アニメーションが停止する時 | |
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { | |
// 自分を唯一参照している親viewから取り除く事でメモリを解放する | |
[self removeFromSuperview]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment