zoukankan      html  css  js  c++  java
  • Xcode9学习笔记60

        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            let rect = CGRect(x: 58, y: 40,  200, height: 200)
            let imageView = UIImageView(frame: rect)
            let image = UIImage(named: "Pic")
            imageView.image = image//给图像视图指定要显示的图片
            imageView.tag = 1//设置图像视图的标识值,以方便后期对图像视图的调用
            
            self.view.addSubview(imageView)
            
            let button = UIButton(type: UIButtonType.system)//初始化一个按钮对象,点击按钮时播放动画
            button.frame = CGRect(x: 58, y: 400,  200, height: 44)
            button.backgroundColor = UIColor.lightGray
            button.setTitle("Tap", for: UIControlState())
            button.addTarget(self, action: #selector(ViewController.playAnimation), for: UIControlEvents.touchUpInside)
            
            self.view.addSubview(button)
        }
        
        @objc func playAnimation() {
            UIView.beginAnimations(nil, context: nil)//发出开始动画的请求
            UIView.setAnimationCurve(.easeOut)//设置动画的播放速度为淡入淡出
            UIView.setAnimationDuration(5)//设置动画时长5秒
            UIView.setAnimationBeginsFromCurrentState(true)//设置动画从当前状态开始播放
            let view = self.view.viewWithTag(1)//通过标识值找到之前创建的图像视图,作为动画的载体
            UIView.setAnimationTransition(.curlUp, for: view!, cache: true)//设置动画类型为翻转动画
            UIView.commitAnimations()//调用视图的提交动画方法,标志着动画块的结束
        }
    

      

  • 相关阅读:
    Photoshop 基础七 位图 矢量图 栅格化
    Photoshop 基础六 图层
    Warfare And Logistics UVALive
    Walk Through the Forest UVA
    Airport Express UVA
    Guess UVALive
    Play on Words UVA
    The Necklace UVA
    Food Delivery ZOJ
    Brackets Sequence POJ
  • 原文地址:https://www.cnblogs.com/LisenH/p/7855795.html
Copyright © 2011-2022 走看看