你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> 雪花飄落效果

雪花飄落效果

編輯:IOS開發綜合

- (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

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved