Spring動(dòng)畫
Spring動(dòng)畫是一種特殊的動(dòng)畫曲線,自從iOS7之后開始被廣泛應(yīng)用在系統(tǒng)動(dòng)畫中兼呵。所謂的Spring動(dòng)畫就是動(dòng)畫在執(zhí)行的過程中會(huì)有一個(gè)放大的效果兔辅,然后在回去腊敲。
創(chuàng)建Spring動(dòng)畫用到了下面的一個(gè)方法
- (void)springAnimation{
//Damping:阻尼值0 - 1、阻尼值越小動(dòng)畫越明顯
//Velocity:初始速度
[UIView animateWithDuration:2.0 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:20
options:UIViewAnimationOptionRepeat animations:^{
self.redView.frame = CGRectMake(100, 300, 200, 200);
self.redView.backgroundColor =[UIColor blackColor];
} completion:nil];
}
Block動(dòng)畫
Block簡單動(dòng)畫
示例:在Block的回調(diào)方法內(nèi)改變動(dòng)畫的顏色
[UIView animateWithDuration:5 animations:^{
//需要改變的屬性
self.redView.backgroundColor = [UIColor cyanColor];
}];
Block復(fù)雜動(dòng)畫
相比較Block的簡單動(dòng)畫來說Block的復(fù)雜動(dòng)畫能夠在動(dòng)畫完成后幢妄,對動(dòng)畫做一些其他的操作
示例:在動(dòng)畫過程中改變將視圖的顏色改為黃色兔仰,在動(dòng)畫結(jié)束的時(shí)候?qū)⒁晥D的顏色改為紅色茫负。
[UIView animateWithDuration:2.0 animations:^{
self.redView.backgroundColor = [UIColor yellowColor];
} completion:^(BOOL finished) {
if (finished) {//動(dòng)畫結(jié)束
self.redView.backgroundColor = [UIColor redColor];
}
}];
GIF動(dòng)圖
簡單來說蕉鸳,gif圖片就是將一組圖片放在一起,以極快的速度切換圖片忍法,這樣就能實(shí)現(xiàn)一個(gè)動(dòng)畫的效果潮尝。西面來看具體的做法。
- 首先饿序,我們創(chuàng)建一個(gè)可變數(shù)組把我們需要用到的圖象存儲(chǔ)起來勉失。
NSMutableArray *imageArray = [NSMutableArray array];
for (int i = 1; i < 14; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"1-%d.tiff",i]];
[imageArray addObject:image];
}
- 然后創(chuàng)建一個(gè)imageView來顯示圖片
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
imageView.center = self.view.center;
imageView.animationImages = imageArray;
imageView.animationDuration = 0.5;//動(dòng)畫執(zhí)行的時(shí)間
imageView.animationRepeatCount = 10;//動(dòng)畫重復(fù)次數(shù)
[self.view addSubview:_imageView];//開啟動(dòng)畫
[imageView startAnimating];
在實(shí)際使用的過程中,通常我們會(huì)在不同的地方原探,來執(zhí)行動(dòng)畫屬性的操作乱凿,具體情況按照需求來實(shí)現(xiàn)。