日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图片浏览(CATransition)转场动画

發布時間:2025/6/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图片浏览(CATransition)转场动画 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Main.storyboard

ViewController.m

//

//? ViewController.m

//? 8A04.圖片瀏覽(轉場動畫)

//

//? Created by huan on 16/2/4.

//? Copyright ? 2016 huanxi. All rights reserved.

//

?

#import "ViewController.h"

#define AnimationDuration 2

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

-(IBAction)tapView:(UITapGestureRecognizer *)sender;

@property (nonatomic, strong) NSMutableArray *imgs;

@property (nonatomic, assign) NSInteger currentImgIndex;//當前的索引

@end

?

@implementation ViewController

?

-(NSMutableArray *)imgs{

? ? if (!_imgs) {

? ? ? ? _imgs = [NSMutableArray array];

? ? ? ? for (NSInteger i = 1; i < 10; i++) {

? ? ? ? ? ? NSString *imgName = [NSString stringWithFormat:@"%ld",i];

? ? ? ? ? ? [_imgs addObject:imgName];

? ? ? ? }

? ? }

? ? return _imgs;

}

?

- (void)viewDidLoad {

? ? [super viewDidLoad];

? ? // Do any additional setup after loading the view, typically from a nib.

? ? NSLog(@"%@",self.imgs);

}

?

- (void)didReceiveMemoryWarning {

? ? [super didReceiveMemoryWarning];

? ? // Dispose of any resources that can be recreated.

}

?

-(IBAction)tapView:(UITapGestureRecognizer *)tap{

? ? //實現判斷圖片的左半邊還是右半邊

? ? //獲取觸摸點

? ? CGPoint point = [tap locationInView:tap.view];

? ? NSLog(@"%@", NSStringFromCGPoint(point));

?? ?

? ? if (point.x <= tap.view.bounds.size.width *0.5) {

? ? ? ? NSLog(@"上一張");

? ? ? ? [self previous];

? ? }else{

? ? ? ? NSLog(@"下一張");

? ? ? ? [self next];

? ? }

?? ?

}

?

-(void)previous{

? ? //判斷當前圖片是不是第一張

? ? if (self.currentImgIndex == 0) {

? ? ? ? return;

? ? }

?? ?

? ? //減索引 改圖片

? ? self.currentImgIndex --;

? ? self.imageView.image = [UIImage imageNamed:self.imgs[self.currentImgIndex]];

? ? //轉場動畫

? ? CATransition *animation = [CATransition animation];

? ? animation.type = @"push";

? ? //默認就是fromLeft

? ? animation.subtype = @"fromLeft";

? ? animation.duration = AnimationDuration;

? ? [self.imageView.layer addAnimation:animation forKey:nil];

}

?

/**

?* 提示:轉場動畫的類型(type)和子類型(subtype)能用字符串常量就用字符串常量

?*/

?

?

/**

?*******************************************************

?type:動畫類型(比如:滴水效果,翻轉效果...)

?-------------------------------------------------------

?fade kCATransitionFade 交叉淡化過渡

?moveIn kCATransitionMoveIn 新視圖移到舊視圖上面

?push kCATransitionPush 新視圖把舊視圖推出去

?reveal kCATransitionReveal 將舊視圖移開,顯示下面的新視圖

?pageCurl ? ? ? ? ? ? ? 向上翻一頁

?pageUnCurl ? ? ? ? ? ? 向下翻一頁

?rippleEffect ? ? ? ? ? ? 滴水效果

?suckEffect 收縮效果,如一塊布被抽走

?cube ? ? ? ? ? ? ? ? ? 立方體效果

?oglFlip? ? ? ? ? ? ? 上下左右翻轉效果

?rotate ? ? 旋轉效果

?cameraIrisHollowClose 相機鏡頭關上效果(不支持過渡方向)

?cameraIrisHollowOpen 相機鏡頭打開效果(不支持過渡方向)

?

?*******************************************************

?subtype: 動畫方向(比如說是從左邊進入,還是從右邊進入...)

?------------------------------------------------------

?kCATransitionFromRight;

?kCATransitionFromLeft;

?kCATransitionFromTop;

?kCATransitionFromBottom;

?

? type @"rotate"(旋轉)的時候,它也有幾個對應的 subtype,分別為:

?90cw 逆時針旋轉 90°

?90ccw 順時針旋轉 90°

?180cw 逆時針旋轉 180°

?180ccw? 順時針旋轉 180°

?**/

-(void)next{

?? ? ? //判斷當前圖片是不是最好一張

? ? if(self.currentImgIndex == self.imgs.count - 1){

? ? ? ? NSLog(@"已經是最好一張");

? ? ? ? return;

? ? }

?? ?

? ? //加索引 改圖片

? ? self.currentImgIndex ++;

? ? self.imageView.image = [UIImage imageNamed:self.imgs[self.currentImgIndex]];

? ? //設置圖片的時候,使用轉場動畫

? ? CATransition *animation = [CATransition animation];

?? ?

? ? //設置轉場動畫的類型

//? ? `fade', `moveIn', `push' and `reveal'.

? ? //fade 漸變 moveIn 直接移動

? ? animation.type = @"rotate";

//? ? animation.type = kCATransitionPush;

? ? //設置轉場動畫的子類型

//? ? `fromLeft', `fromRight', `fromTop' and

//? ? * `fromBottom'? fromLeft 從左邊開始推

? ? animation.subtype = @"90cw";

? ? animation.duration = AnimationDuration;

? ? [self.imageView.layer addAnimation:animation forKey:nil];

}

?

@end

?

?

轉載于:https://www.cnblogs.com/Lu2015-10-03/p/5191336.html

總結

以上是生活随笔為你收集整理的图片浏览(CATransition)转场动画的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。