ios動畫編程

//web

//  ViewController.swift編程

//  iOS 動畫編程swift

//ide

//  Created by Macx on 18/9/16.動畫

//  Copyright (c) 2018年 learn. All rights reserved.url

//代理

 

import UIKitwebview

 

class ViewController: UIViewController {rem

    //綁定myview視圖animation

    @IBOutlet weak var myview: UIView!

    @IBOutlet weak var myview2: UIView!

    @IBOutlet weak var myview3: UIView!

    @IBOutlet weak var mywebview: UIWebView!

    

    var mOriginFrame = CGRect()  //記錄位置

    var mOriginFrame2 = CGRect()

    var mOriginFrame3 = CGRect()

    override func viewDidLoad() {

        super.viewDidLoad()

        

        self.mOriginFrame = self.myview.frame

        self.mOriginFrame2 = self.myview2.frame

        self.mOriginFrame3 = self.myview3.frame

        mywebview.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.baidu.com")!))

    }

 

    //start按鈕

    @IBAction func start(sender: AnyObject) {

        /*

 

        })

       */

        self.optionAnimate()

        self.OPerateSubview()

        

    }

    //fallback按鈕

    @IBAction func fallback(sender: AnyObject) {

 

        self.myview.frame = mOriginFrame

        self.myview2.frame = mOriginFrame2

        self.myview3.frame = mOriginFrame3

        self.myview.layer.removeAllAnimations()

    }

    

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

    //設置start的操做 block方法

    func optionAnimate(){

        UIView.animateWithDuration(2.0, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in

            self.myview.frame.origin.x += 100

            

            //內層動畫屬性設置,重寫父類方法

            UIView.animateWithDuration(10, delay: 0, options:UIViewAnimationOptions.OverrideInheritedDuration | UIViewAnimationOptions.OverrideInheritedCurve |

                //設置曲線

                UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in

                    

                self.myview2.frame.origin.x += 100

                    

            }, completion: { (finish) -> Void in

                print("inner animate finished")

            })

        }) { (finish) -> Void in

            print("outnner animate finished")

        }

    

    }

    //設置start的操做 beginCommitAnimate方法

    func beginCommitAnimate(){

        //聲明動畫開始並配置屬性

        UIView.beginAnimations("testAnimate", context: nil)

        UIView.setAnimationDuration(2.0)

        UIView.setAnimationRepeatAutoreverses(true)

        UIView.setAnimationRepeatCount(7)

        UIView.setAnimationDelegate(self)

        UIView.setAnimationWillStartSelector("animationDidStart:")

        UIView.setAnimationDidStopSelector("animationDidStop:finished:")

        //操做視圖

        self.myview.backgroundColor = UIColor.magentaColor()

        

        //提交動畫

        UIView.commitAnimations()

    

    }

    //Animation 代理方法

    override func animationDidStart(anim: CAAnimation!) {

        print("Animation start")

    }

    override func animationDidStop(anim: CAAnimation!, finished flag: Bool) {

        print("Animation stop")

    }

    //myview3代理方法

    func OPerateSubview(){

        UIView.transitionWithView(self.myview3, duration: 2, options: UIViewAnimationOptions.TransitionCurlUp | UIViewAnimationOptions.AllowAnimatedContent, animations: { () -> Void in

            self.myview3.frame.origin.x += 190

        }) { (finish) -> Void in

            print("finished")

        }

    }

    

}

相關文章
相關標籤/搜索