- 论坛徽章:
- 0
|
雪花飘落效果
Ios代码- 1.- (void)viewDidLoad {
- 2. [super viewDidLoad];
- 3. flakeImage = [UIImage imageNamed:@"flake.png"];
- 4. [NSTimer scheduledTimerWithTimeInterval:(0.05) target:self selector:@selector(play) userInfo:nil repeats:YES];
- 5.}
- 6.
- 7.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- 8. return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
- 9.}
- 10.
- 11.- (void)play {
- 12. UIImageView *flakeView = [[UIImageView alloc] initWithImage:flakeImage];
- 13. int startX = round(random() % 1024);
- 14. int endX = round(random() % 1024);
- 15. double scale = 1 / round(random() % 100) + 1.0;
- 16. double speed = 1 / round(random() % 100) + 1.0;
- 17. flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
- 18. flakeView.alpha = 0.55;
- 19. [self.view addSubview:flakeView];
- 20. [UIView beginAnimations:nil context:flakeView];
- 21. [UIView setAnimationDuration:5 * speed];
- 22. flakeView.frame = CGRectMake(endX, 768.0, 25.0 * scale, 25.0 * scale);
- 23. [UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
- 24. [UIView setAnimationDelegate:self];
- 25. [UIView commitAnimations];
- 26.}
- 27.
- 28.- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
- 29. UIImageView *flakeView = context;
- 30. [flakeView removeFromSuperview];
- 31. [flakeView release];
- 32.}
- - (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];
- }
复制代码 示例图:
|
|