@interface ViewController () { UIImage *image; } - (IBAction)didAction:(id)sender; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor cyanColor]; //雪花圖片 image = [UIImage imageNamed:@"iconfont-xuehua"]; //啓動定時器 [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(showTime) userInfo:nil repeats:YES]; // Do any additional setup after loading the view, typically from a nib. } - (void)showTime { //建立雪花 UIImageView *imageV = [[UIImageView alloc] initWithImage:image]; //添加 [self.view addSubview:imageV]; NSInteger startX = arc4random()%356 + 10; //雪花開始位置 imageV.frame = CGRectMake(startX, 50, 50, 50); //動畫 [UIView animateWithDuration:2 animations:^{ //雪花下落位置 imageV.frame = CGRectMake(startX, self.view.frame.size.height, 30, 30); } completion:^(BOOL finished) { //動畫完成移除雪花 [imageV removeFromSuperview]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)didAction:(id)sender { WebViewController *web = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil]; [self.navigationController pushViewController:web animated:YES]; } @end