先寫出基本的東西
@IBAction func leftBtnClick(sender: AnyObject) {
index -= 1
if (index == 0)
{
index = 9
}
let image = UIImage.init(named: "\(index).jpg")
imageV.image = image
}
@IBAction func rightBtnClick(sender: AnyObject) {
index+=1
if (index == 10)
{
index = 1
}
let image = UIImage.init(named: "\(index).jpg")
imageV.image = image
}
設置了type=cube,subType= kCATransitionFromRight或者kCATransitionFromLeft,如果是cube的情況,默認是向上的
在其中我們設置一個
cube
3d的效果盖呼,代碼如下
//寫在leftBtnClick底部
//2.設置轉(zhuǎn)場動畫效果
transitionAnim.type = "cube"
transitionAnim.subtype = kCATransitionFromRight
//3.設置時間
transitionAnim.duration = 0.4
//添加動畫到layer
self.imageV.layer.addAnimation(transitionAnim, forKey: "23")
//寫在rightBtnClick底部
//1.創(chuàng)建動畫對象
let transitionAnim = CATransition()
//2.設置轉(zhuǎn)場動畫效果
transitionAnim.type = "cube"
transitionAnim.subtype = kCATransitionFromLeft
//3.設置時間
transitionAnim.duration = 0.4
//添加動畫到layer
self.imageV.layer.addAnimation(transitionAnim, forKey: "23")
type
的幾種樣式動畫效果免都,可以通過swift的常量盏求,或者是傳遞特定的字符串
/* Common transition types. */
//交叉淡化過度(不支持方向)
1.fade 或者 kCATransitionFade
//新的視圖移到舊的視圖上邊去
2.moveIn 或者 kCATransitionMoveIn
//新的視圖將過去的視圖推出去
3.push 或者 kCATransitionPush
//將舊視圖移開福侈,顯示下邊的新視圖
4.reveal 或者 kCATransitionReveal
//立方體翻滾效果
5.cube
//上下左右翻滾效果
6.oglFlip
//收縮效果戚揭,如一塊布被抽走(不支持過度的方向)
7.suckEffect
//滴水效果(不支持方向)
8.rippleEffect
//向上翻頁效果
9.pageCurl
//向下翻頁效果
10.pageUnCurl
type = "pageCurl",剛才的方向代碼沒刪除挨下,還是左右的~
rippleEffect水滴效果
轉(zhuǎn)場的方向腰湾,就是4個粉怕,上下左右
再說兩個轉(zhuǎn)場動畫的兩個屬性
1.startProgress(動畫起點腹尖,在整個動畫的百分比)
2.endProgress(動畫終點掠手,在整個動畫的百分比)
兩者都是[0,1],默認是0憾朴,可以只設置一個,如果設置了兩個喷鸽,那么結(jié)束的一定要大約開始
上一頁是startPro = 0众雷,下一頁是0.5的效果
結(jié)束的就不用講了哈~