
@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
}

在其中我们设置一个
cube
3d的效果,代码如下
//写在leftBtnClick底部
//2.设置转场动画效果
transitionAnim.type = "cube"
transitionAnim.subtype = kCATransitionFromRight
//3.设置时间
transitionAnim.duration = 0.4
//添加动画到layer
self.imageV.layer.addAnimation(transitionAnim, forKey: "23")
//写在rightBtnClick底部
//1.创建动画对象
let transitionAnim = CATransition()
//2.设置转场动画效果
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


转场的方向,就是4个,上下左右
再说两个转场动画的两个属性
1.startProgress(动画起点,在整个动画的百分比)
2.endProgress(动画终点,在整个动画的百分比)
两者都是[0,1],默认是0,可以只设置一个,如果设置了两个,那么结束的一定要大约开始

结束的就不用讲了哈~
网友评论