swift ios转场动画详解
来源:互联网 发布:linux nano vim 编辑:程序博客网 时间:2024/05/20 02:22
1.前言
转载请注明出处
http://blog.csdn.net/wangguoyang429883793/article/details/50385423
不得不惊叹ios的动画封装!
2.转场动画
1.比较简单,直接上代码了。最后会有demo。
let cnt = 3 //图片数量 var currentIndex = 0 var img:UIImageView? var imgs:[UIImage] = [] //要展示的图片容器 var transitionType = "rippleEffect" private(set) var isNext: Bool { get{ return true } set { layerTransitionAnimation(newValue) //启动动画 } } override func viewDidLoad() { addImageView() addOptionsBtn() } func addImageView(){ //定义图片控件 img = UIImageView(frame: self.view.bounds) img?.contentMode = .ScaleAspectFit img?.image = UIImage(named: "tangwei") self.view.addSubview(img!) //添加手势 let leftSwipGesture = UISwipeGestureRecognizer(target: self, action: "onLeftSwipe:") leftSwipGesture.direction = .Left self.view.addGestureRecognizer(leftSwipGesture) let rightSwipeGesture = UISwipeGestureRecognizer(target: self, action: "onRightSwipe:") rightSwipeGesture.direction = .Right self.view.addGestureRecognizer(rightSwipeGesture) imgs.append(UIImage(named: "tangwei")!) imgs.append(UIImage(named: "gaoyuanyuan1")!) imgs.append(UIImage(named: "gaoyuanyuan2")!) } func onLeftSwipe(gesture:UISwipeGestureRecognizer){ isNext = true } func onRightSwipe(gesture:UISwipeGestureRecognizer){ isNext = false } //转场动画 func layerTransitionAnimation(isnext:Bool){ //1.创建转场动画对象 let transition = CATransition() //水波效果 transition.type = transitionType //设置子类型 if (isnext) { transition.subtype = kCATransitionFromRight }else{ transition.subtype = kCATransitionFromLeft } transition.duration = 1.0 img?.layer.addAnimation(transition, forKey: "") img?.image = getImage(isnext) } // 获取当前应该展示的图片 func getImage(isnext:Bool)->UIImage{ if (isnext) { currentIndex = (currentIndex+1)%cnt }else{ currentIndex = (currentIndex-1+cnt)%cnt } return imgs[currentIndex] } func addOptionsBtn(){ let btn = UIButton(frame: CGRectMake(0,0,100,60)) btn.setTitle("动画效果", forState: .Normal) btn.setTitleColor(UIColor.redColor(), forState: .Normal) btn.addTarget(self, action: "onClick", forControlEvents: .TouchUpInside) self.view.addSubview(btn) btn.center = CGPoint(x: UIScreen.mainScreen().bounds.width - 60 , y: 64) } func onClick(){ showOptions() } //其他效果选项 func showOptions(){ let actionSheet = UIActionSheet() actionSheet.addButtonWithTitle("骰子效果") actionSheet.addButtonWithTitle("翻转效果") actionSheet.addButtonWithTitle("收缩效果") actionSheet.addButtonWithTitle("向上翻页效果") actionSheet.addButtonWithTitle("向下翻页效果") actionSheet.addButtonWithTitle("摄像头打开效果") actionSheet.addButtonWithTitle("摄像头关闭效果") actionSheet.addButtonWithTitle("水波效果") actionSheet.delegate = self actionSheet.showInView(self.view) } func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) { switch(buttonIndex){ case 0: transitionType = "cube" case 1: transitionType = "oglFlip" case 2: transitionType = "suckEffect" case 3: transitionType = "pageCurl" case 4: transitionType = "pageUnCurl" case 5: transitionType = "cameralIrisHollowOpen" case 6: transitionType = "cameraIrisHollowClose" case 7: transitionType = "rippleEffect" default: break } }
其实UIView.transitionWithView 也可以,但是没有这么多得效果。
demo:http://download.csdn.net/detail/wangguoyang429883793/9373376
3.总结
参考地址http://www.cnblogs.com/kenshincui/p/3972100.html
欢迎批评,吐槽,点赞,留言。
1 0
- swift ios转场动画详解
- iOS转场动画详解
- iOS 卡片转场动画 Swift
- Swift自定义转场动画
- Swift转场动画类型
- swift中的转场动画
- iOS视图控制器转场动画详解
- [iOS Swift] 自定义转场动画 UIViewControllerAnimatedTransitioning 报错
- iOS那些简单的动画,属性详解和转场动画
- iOS之转场动画/自定义转场动画
- swift中基本转场动画.
- UIView转场动画 IOS
- iOS 导航转场动画
- iOS自定义转场动画
- ios 转场动画
- iOS自定义转场动画
- ios-转场动画
- iOS 转场动画等
- Ubuntu 13.10 64bit 不能运行 32bit的软件
- 【geoip】geoip操作GeoLiteCity.dat
- 你对做水晶头还有疑问吗?
- BLE发送接收任意字节数据
- H264的I/P/B帧类型判断
- swift ios转场动画详解
- 网络爬虫——爬取糗事百科笑料段子
- 创建实例失败 state error
- 设计模式之适配器
- OC学习篇之-----类目·延展·协议之--类目
- ResourceBundle
- oracle 日期函数 MONTHS_BETWEEN
- 解决UICollectionView的cell间距与设置不符问题
- 成功的背后!(给所有IT人)