- (void)viewDidLoad {
[super viewDidLoad];
flakeImage = [UIImage imageNamed:@"flake.png"];
[NSTimer scheduledTimerWithTimeInterval:(0.05) target:self selector:@selector(play) userInfo:nil repeats:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
- (void)play {
UIImageView *flakeView = [[UIImageView alloc] initWithImage:flakeImage];
int startX = round(random() % 1024);
int endX = round(random() % 1024);
double scale = 1 / round(random() % 100) + 1.0;
double speed = 1 / round(random() % 100) + 1.0;
flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
flakeView.alpha = 0.55;
[self.view addSubview:flakeView];
[UIView beginAnimations:nil context:flakeView];
[UIView setAnimationDuration:5 * speed];
flakeView.frame = CGRectMake(endX, 768.0, 25.0 * scale, 25.0 * scale);
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
UIImageView *flakeView = context;
[flakeView removeFromSuperview];
[flakeView release];
}
- (void)viewDidLoad {
[super viewDidLoad];
flakeImage = [UIImage imageNamed:@"flake.png"];
[NSTimer scheduledTimerWithTimeInterval:(0.05) target:self selector:@selector(play) userInfo:nil repeats:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
- (void)play {
UIImageView *flakeView = [[UIImageView alloc] initWithImage:flakeImage];
int startX = round(random() % 1024);
int endX = round(random() % 1024);
double scale = 1 / round(random() % 100) + 1.0;
double speed = 1 / round(random() % 100) + 1.0;
flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
flakeView.alpha = 0.55;
[self.view addSubview:flakeView];
[UIView beginAnimations:nil context:flakeView];
[UIView setAnimationDuration:5 * speed];
flakeView.frame = CGRectMake(endX, 768.0, 25.0 * scale, 25.0 * scale);
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
UIImageView *flakeView = context;
[flakeView removeFromSuperview];
[flakeView release];
}
樣本圖:
作者 jsntghf