View动画i

class ViewController: UIViewController {
    @IBOutlet weak var redView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }

    @IBAction func didStartClicked(sender: UIButton) {
        
        //动画总时长、通过UIView的一些属性
//        UIView.animateWithDuration(10) {
//            //只对UIView的属性有作用
//            self.redView.frame = CGRect(x: 100, y: 100, width: 200, height: 200)
//            self.redView.backgroundColor = UIColor.greenColor()
////            self.redView.layer.cornerRadius = 100
//        }
        
//        UIView.animateWithDuration(5, animations: { 
//            self.redView.backgroundColor = UIColor.yellowColor()
//            }) { (completion) in
//                print("动画执行完成了")
//        }
        //option: 重复、自动回复,   completion(完成时机)
//        UIView.animateWithDuration(1, delay: 0, options: [.Repeat, .Autoreverse], animations: {
//            self.redView.frame = CGRect(x: 200, y: 200, width: 50, height: 50)
//            
//            }, completion: nil)
        
        //POP
        
        //1. 开始设置动画
        UIView.beginAnimations("first", context: nil)
        
        //2. 设置动画属性
        UIView.setAnimationDuration(10)
        UIView.setAnimationRepeatCount(2)
        UIView.setAnimationDelegate(self) //设置代理方法所在的对象
        UIView.setAnimationWillStartSelector(#selector(animateWillStart(_:context:)))
        UIView.setAnimationDidStopSelector(#selector(animateDidStop(_:finished:context:)))
        
        //3. 设置目标属性
        self.redView.backgroundColor = UIColor.greenColor()
        
        //4. 提交动画,开始执行
        UIView.commitAnimations()
    }

    //animationWillStart:(NSString *)animationID context:(void *)context
    func animateWillStart(animationID: NSString, context: UnsafePointer<Void>) {
        print("will start")
    }
    
    //NSNumber
    func animateDidStop(animationID: NSString, finished: Bool, context: UnsafePointer<Void>) {
        print(finished)
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS中的动画 iOS系统中的应用大多都灵活运用了各种各样的动画来让自己的应用变的丰富多彩,一个App对动画的运用...
    Hydrogen_阅读 4,714评论 0 1
  • 2014年09月23日 9695 愿你纵深一跃,不惧深渊。愿风暴降临,你岸堤永固。愿人群声嘶力竭,呼喊你名。愿众人...
    林妖妖的盛夏光年阅读 5,649评论 0 7
  • 这次换了一班到达汉口的高铁,即将到达信阳,寒假结束我也即将继续开始我的新学期了。 我这次真是难得的心慌意乱,忐忑不...
    霍稀泥阅读 1,430评论 0 0
  • 昨天,看了我们班孙宝钧妈妈 写的一篇日记,她和儿子在游戏中学习,受到了她的影响,今天我和宝贝儿们也...
    O卓越O阅读 861评论 0 0
  • R语言中对小数点的位数的设置 经常用数据分析,有时不同的文件的小数位数不一样,但是我们可以让它们的位数保持一致的,...
    Bioconductor阅读 13,720评论 0 4