常見的轉場動畫
方案1:
//創建轉場動畫對象
CATransition *transition = [[CATransition alloc]init];
/* The name of the transition. Current legal transition types include
* `fade', `moveIn', `push' and `reveal'. Defaults to `fade'. */
/**
* 1.#define定義的常量
kCATransitionFade 交叉淡化過渡 默許
kCATransitionMoveIn 新視圖移到舊視圖上面,覆蓋原圖
kCATransitionPush 新視圖把舊視圖推出去 ,推出
kCATransitionReveal 將舊視圖移開,顯示下面的新視圖 ,從底部顯示
2.用字符串表示
pageCurl 向上翻1頁
pageUnCurl 向下翻1頁
rippleEffect 滴水效果
suckEffect 收縮效果,如1塊布被抽走
cube 立方體效果
oglFlip 上下翻轉效果
注意:
還有很多私有API效果,使用的時候要謹慎,可能會致使app審核不被通過(悲劇啊,為啥有卻不讓用啊!好東西不應當被置之不理!)
fade //交叉淡化過渡(不支持過渡方向)
push //新視圖把舊視圖推出去
moveIn //新視圖移到舊視圖上面
reveal //將舊視圖移開,顯示下面的新視圖
cube //立方體翻滾效果
oglFlip //上下左右翻轉效果
suckEffect //收縮效果,如1塊布被抽走(不支持過渡方向)
rippleEffect //滴水效果(不支持過渡方向)
pageCurl //向上翻頁效果
pageUnCurl //向下翻頁效果
cameraIrisHollowOpen //相機鏡頭打開效果(不支持過渡方向)
cameraIrisHollowClose //相機鏡頭關上效果(不支持過渡方向)
*/
//設置動畫類型,注意對蘋果官方沒有公然的動畫類型智能使用字符串,并沒有對應的常量意義
// transaction.type=@"pageCurl";//控制圖片的滑動類型
if (isNext == YES) {
transition.type = @"pageCurl";
transition.subtype = kCATransitionFromRight;
} else {
transition.type = @"cube";
transition.subtype = kCATransitionFromLeft;
}
//設置動畫時長,默許為0
transition.duration=1.0;
/* The amount of progress through to the transition at which to begin
* and end execution. Legal values are numbers in the range [0,1].
* `endProgress' must be greater than or equal to `startProgress'.
* Default values are 0 and 1 respectively. */
//動畫開始的進度
// transaction.startProgress=0.1;
//動畫結束的進度,,,結束的進度必須大于開始的進度
// transaction.endProgress=0.5;
//動畫的速度
// transaction.speed=100.0;
//設置轉場后的新視圖添加轉場動畫
self.imageView.image=[self transitionImage:isNext];
//添加動畫效果
[self.imageView.layer addAnimation:transition forKey:@"Animation"];
畫方案2:
可以直接調用下面這個函數
[UIView transitionFromView:view2 toView:view1 duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
//這個api 原理 :
// 1:[fromvalue.superview addSubview:tovalue];
// 2:[fromvalue removeFromSuperview];
// NSLog(@"fromvalue-->%@",fromvalue.superview);
// NSLog(@"tovalue-->%@",tovalue.superview);
}];
下一篇 Jquery實現拖拽可編輯模塊