Animation
UIImageView
NSMutableArray *allImages = [NSMutableArray array];
for (NSInteger i = 0; i < 32; i++) {
//拼接圖片的名稱
NSString *fileName = [NSString stringWithFormat:@"yinJiaoDaWang%02ld",i+1];
//創(chuàng)建圖片對(duì)象
UIImage *image = [UIImage imageNamed:fileName];
//將創(chuàng)建好的圖片 添加到數(shù)組中
[allImages addObject:image];
}
//設(shè)置 動(dòng)畫所需圖片 (需要的是一個(gè)圖片數(shù)組)
self.npcImageView.animationImages = allImages;
//設(shè)置動(dòng)畫的時(shí)長(zhǎng) (一次多長(zhǎng)時(shí)間)
self.npcImageView.animationDuration = 1 / 10.0 * 32;
//設(shè)置動(dòng)畫運(yùn)行次數(shù) 值為0 是無限運(yùn)行
self.npcImageView.animationRepeatCount = 0;
//運(yùn)行動(dòng)畫
[self.npcImageView startAnimating];
if (self.npcImageView.animationRepeatCount != 0) {
//動(dòng)畫運(yùn)行完 要釋放動(dòng)畫數(shù)組
//獲取動(dòng)畫總時(shí)間
CGFloat afterDelay = self.npcImageView.animationDuration * self.npcImageView.animationRepeatCount;
//等待 afterDelay 時(shí)間后 向 self.npcImageView 發(fā)送setAnimationImages 消息 并把 nil 做為參數(shù)傳給 setAnimationImages 方法
[self.npcImageView performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:afterDelay];
}
#define SPEED 1/15.0
//扔派動(dòng)畫
- (IBAction)pieButtonClick:(id)sender {
[self runAnimationWithImageView:self.tomImageView imageFileName:@"pie_" imageCount:24 speed:SPEED];
}
-(void)runAnimationWithImageView:(UIImageView*)imageView imageFileName:(NSString*)imageFileName imageCount:(NSInteger)imageCount speed:(CGFloat)speed {
//判斷imageView 是否正在運(yùn)行動(dòng)畫
if (imageView.isAnimating) return;
NSMutableArray *allImages = [NSMutableArray array];
for (NSInteger i = 0; i < imageCount; i++) {
//拼接圖片的名稱
NSString *fileName = [NSString stringWithFormat:@"%@%02ld",imageFileName, i];
//創(chuàng)建圖片對(duì)象
UIImage *image = [UIImage imageNamed:fileName];
//將創(chuàng)建好的圖片 添加到數(shù)組中
[allImages addObject:image];
}
//設(shè)置 動(dòng)畫所需圖片 (需要的是一個(gè)圖片數(shù)組)
imageView.animationImages = allImages;
//設(shè)置動(dòng)畫的時(shí)長(zhǎng) (一次多長(zhǎng)時(shí)間)
imageView.animationDuration = speed * imageCount;
//設(shè)置動(dòng)畫運(yùn)行次數(shù) 值為0 是無限運(yùn)行
imageView.animationRepeatCount = 1;
//運(yùn)行動(dòng)畫
[imageView startAnimating];
}
UIView
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[UIView animateWithDuration:2 animations:^{
//設(shè)置動(dòng)畫的最終狀態(tài)
self.imageView.alpha = 1;
CGPoint center = self.imageView.center;
center.y += 300;
self.imageView.center = center;
}];
[UIView animateWithDuration:2 animations:^{
self.imageView.alpha = 1;
} completion:^(BOOL finished) {
//動(dòng)畫執(zhí)行完 執(zhí)行 該代碼塊
NSLog(@"動(dòng)畫執(zhí)行完");
}];
/*
Duration 動(dòng)畫持續(xù)時(shí)間
delay 等待時(shí)間
options 動(dòng)畫選項(xiàng) (動(dòng)畫勻速 變速 重復(fù))
animations 動(dòng)畫結(jié)束后什么樣子 (最終狀態(tài))
completion 動(dòng)畫結(jié)束后做什么
*/
[UIView animateWithDuration:2 delay:3 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
CGPoint center = self.imageView.center;
center.y += 300;
self.imageView.center = center;
} completion:nil];
}
- UIView轉(zhuǎn)場(chǎng)動(dòng)畫
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
self.imageIndex++;
if (self.imageIndex > 43) return;
NSString *imageName = [NSString stringWithFormat:@"a%ld",self.imageIndex];
//添加轉(zhuǎn)場(chǎng)動(dòng)畫
[UIView transitionWithView:self.imageView duration:1 options:UIViewAnimationOptionTransitionCurlUp animations:^{
self.imageView.image = [UIImage imageNamed:imageName];
} completion:nil];
}
界面跳轉(zhuǎn)動(dòng)畫
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
MyViewController *myVC = [[MyViewController alloc]init];
/*
UIModalTransitionStyleCoverVertical
UIModalTransitionStyleFlipHorizontal
UIModalTransitionStyleCrossDissolve
UIModalTransitionStylePartialCurl
*/
//設(shè)置跳轉(zhuǎn)動(dòng)畫的類型
myVC.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:myVC animated:YES completion:nil];
}