当前位置:编程学习 > wap >>

雪花飘落效果

- (void)viewDidLoad {  
    [super viewDidLoad];  
    flakeImage = [UIImage imageNamed:@"flake.png"];  
    [NSTimer scheduledTimerWithTimeInterval:(0.05) target:self selector:@selector(play) userInfo:nil repeats:YES];  
}  
 
- (BOOL)shouldAutorotateToInte易做图ceOrientation:(UIInte易做图ceOrientation)inte易做图ceOrientation {  
    return (inte易做图ceOrientation == UIInte易做图ceOrientationLandscapeLeft);  
}  
 
- (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)shouldAutorotateToInte易做图ceOrientation:(UIInte易做图ceOrientation)inte易做图ceOrientation {
       return (inte易做图ceOrientation == UIInte易做图ceOrientationLandscapeLeft);
}
 
- (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

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,