標籤:藍懿教育 劉國斌 ios 培訓
將VIew移動做成動畫效果 這種動畫效果沒有中間的位移
可以添加動畫的View屬性center,frame,alpha,transform , backgroundColor
//繼續做消失的動畫
[UIView animateWithDuration:1 animations:^{
iv.alpha = 0;
} completion:^(BOOL finished) {
//完成動畫後執行 可以繼續添加
[iv removeFromSuperview];
}];
- (void)viewDidLoad {
[super viewDidLoad];
// Do anyadditional setup after loading the view, typically from a nib.
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(addSnow) userInfo:nil repeats:YES];
}
-(void)addSnow{
int size = arc4random()%10+10;
UIImageView *iv = [[UIImageViewalloc]initWithFrame:CGRectMake(arc4random()%(320-size), -size, size, size)];
iv.image = [UIImageimageNamed:@"snow"];
[self.view addSubview:iv];
int time = arc4random()%4+1;
//添加移動動畫
[UIView animateWithDuration:time animations:^{
//移動的終點位置
iv.center = CGPointMake(iv.center.x, 568);
//圖形改變終點形狀
iv.transform = CGAffineTransformRotate(iv.transform, (arc4random()%360)/180.0*M_PI);
} completion:^(BOOLfinished) {
//繼續做雪花消失的動畫
[UIView animateWithDuration:1 animations:^{
iv.alpha = 0;
} completion:^(BOOL finished) {
[iv removeFromSuperview];
}];
}];
}
藍懿教育九月二十七日記錄