最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IOS swift中的動(dòng)畫(huà)的實(shí)例詳解

 更新時(shí)間:2017年09月12日 10:06:51   作者:番薯大佬  
這篇文章主要介紹了IOS swift中的動(dòng)畫(huà)的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文大家能掌握IOS動(dòng)畫(huà)的知識(shí),需要的朋友可以參考下

IOS swift中的動(dòng)畫(huà)的實(shí)例詳解

UIView的通用動(dòng)畫(huà)

let view = UIView(frame: CGRectMake(10.0, 10.0, 100.0, 40.0))
self.view.addSubview(view)
view.backgroundColor = UIColor.lightGrayColor()
// 位置改變
var frame = view.frame
UIView.animateWithDuration(0.6, delay: 2.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
      () -> Void in

      frame.origin.x = 200.0
      view.frame = frame

      }) {
        (finished:Bool) -> Void in

        UIView.animateWithDuration(0.6) {
          () -> Void in

          frame.origin.x = 10.0
          view.frame = frame
        }
}

CABasicAnimation核心動(dòng)畫(huà)

1、CABasicAnimation類(lèi)只有三個(gè)屬性:

fromValue:開(kāi)始值 
toValue:結(jié)束值 
Duration:動(dòng)畫(huà)的時(shí)間 
repeatCount:重復(fù)次數(shù)

2、通過(guò)animationWithKeyPath鍵值對(duì)的方式設(shè)置不同的動(dòng)畫(huà)效果

transform.scale 
transform.scale.x 
transform.scale.y 
transform.rotation.z 
opacity 
margin 
zPosition 
backgroundColor 
cornerRadius 
borderWidth 
bounds 
contents 
contentsRect 
cornerRadius 
frame 
hidden 
mask 
masksToBounds 
opacity 
position 
shadowColor 
shadowOffset 
shadowOpacity 
shadowRadius
let view = UILabel(frame: CGRectMake((self.view.frame.size.width - 200.0) / 2, 10.0, 200.0, 40.0))
self.view.addSubview(view)
view.text = "縮放/淡入淡出"
view.textAlignment = .Center
view.adjustsFontSizeToFitWidth = true
view.backgroundColor = UIColor.lightGrayColor()
//
let layer = view.layer
// 開(kāi)始動(dòng)畫(huà)
// 縮放
let scaleAnimate = CABasicAnimation(keyPath: "transform.scale")
scaleAnimate.fromValue = 1.0
scaleAnimate.toValue = 1.5
scaleAnimate.autoreverses = true
scaleAnimate.repeatCount = MAXFLOAT
scaleAnimate.duration = 1.0
// 淡入淡出
let opaqueAnimate = CABasicAnimation(keyPath: "opacity")
opaqueAnimate.fromValue = 0.1
opaqueAnimate.toValue = 1
opaqueAnimate.autoreverses = true
opaqueAnimate.repeatCount = MAXFLOAT
opaqueAnimate.duration = 1.0
layer.addAnimation(scaleAnimate, forKey: "scaleAnimate")
layer.addAnimation(opaqueAnimate, forKey: "opacityAnimate")
// 組合動(dòng)畫(huà)
let view3 = UILabel(frame: CGRectMake(10.0, (currentView.frame.origin.y + currentView.frame.size.height + 10.0), 120.0, 40.0))
self.view.addSubview(view3)
view3.text = "組合動(dòng)畫(huà)"
view3.textAlignment = .Center
view3.adjustsFontSizeToFitWidth = true
view3.backgroundColor = UIColor.lightGrayColor()
//
let layer3 = view3.layer
// CAAnimationGroup組合動(dòng)畫(huà)效果
let rotate: CABasicAnimation = CABasicAnimation()
rotate.keyPath = "tranform.rotation"
rotate.toValue = M_PI
let scale: CABasicAnimation = CABasicAnimation()
scale.keyPath = "transform.scale"
scale.toValue = 0.0
let move: CABasicAnimation = CABasicAnimation()
move.keyPath = "transform.translation"
move.toValue = NSValue(CGPoint: CGPoint(x: 217, y: 230))
let animationGroup:CAAnimationGroup = CAAnimationGroup()
animationGroup.animations = [rotate, scale, move]
animationGroup.duration = 2.0
animationGroup.fillMode = kCAFillModeForwards
animationGroup.removedOnCompletion = false
animationGroup.repeatCount = MAXFLOAT
//
layer3.addAnimation(animationGroup, forKey: nil)

CAKeyframeAnimation關(guān)鍵幀動(dòng)畫(huà)

主要屬性:

keyPath : 要設(shè)置的屬性 
path : 路徑 可用UIBezierPath(設(shè)置了path,將忽略values) 
duration : 動(dòng)畫(huà)時(shí)長(zhǎng) 
repeatCount : 重復(fù)次數(shù) 
calculationMode : 動(dòng)畫(huà)計(jì)算方式 
values:每一個(gè)關(guān)鍵幀(設(shè)置了path,將忽略values) 
removedOnCompletion:執(zhí)行完之后不刪除動(dòng)畫(huà) 
fillMode:執(zhí)行完之后保存最新的狀態(tài) 
delegate:代理

let view = UILabel(frame: CGRectMake((self.view.frame.size.width - 200.0) / 2, 10.0, 200.0, 40.0))
self.view.addSubview(view)
view.text = "CAKeyframeAnimation動(dòng)畫(huà)"
view.backgroundColor = UIColor.lightGrayColor()
//
let layer = view.layer
// 位移
let keyAnimate = CAKeyframeAnimation(keyPath: "position")
// 設(shè)定關(guān)鍵幀
let value0 = NSValue(CGPoint: layer.position)
let value1 = NSValue(CGPoint: CGPointMake(layer.position.x, layer.position.y + 200))
let value2 = NSValue(CGPoint: CGPointMake(layer.position.x - 150, layer.position.y + 200))
let value3 = NSValue(CGPoint: CGPointMake(layer.position.x - 150, layer.position.y))
let value4 = NSValue(CGPoint: layer.position)
// 速度曲線
let tf0 = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
let tf1 = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
let tf2 = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
let tf3 = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
keyAnimate.timingFunctions = [tf0, tf1, tf2, tf3]
// 每段執(zhí)行的時(shí)間
keyAnimate.keyTimes = [0.0, 0.5, 0.6, 0.7, 1]
//
keyAnimate.values = [value0, value1, value2, value3, value4]
keyAnimate.autoreverses = false
keyAnimate.repeatCount = 3
keyAnimate.duration = 6.0
//
keyAnimate.delegate = self
//
layer.addAnimation(keyAnimate, forKey: "position")
// 代理方法
override func animationDidStart(anim: CAAnimation) {
    print("開(kāi)始")
}

override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
    print("結(jié)束")
}

let view3 = UILabel(frame: CGRectMake(10.0, (currentView.frame.origin.y + currentView.frame.size.height + 10.0), 60.0, 60.0))
self.view.addSubview(view3)
view3.text = "抖動(dòng)"
view3.backgroundColor = UIColor.lightGrayColor()
//
let layer3 = view3.layer
// 抖動(dòng)
let animation3 = CAKeyframeAnimation()
animation3.keyPath = "transform.rotation"
// (-M_PI_4 /90.0 * 5)表示-5度 。
let value31 = NSValue(CGPoint: CGPointMake(CGFloat(-M_PI_4 / 90.0 * 5.0), 0.0))
let value32 = NSValue(CGPoint: CGPointMake(CGFloat(M_PI_4 / 90.0 * 5.0), 0.0))
let value33 = NSValue(CGPoint: CGPointMake(CGFloat(-M_PI_4 / 90.0 * 5.0), 0.0))
animation3.values = [value31, value32, value33];
animation3.removedOnCompletion = false
animation3.fillMode = kCAFillModeForwards
animation3.duration = 0.2
animation3.repeatCount = MAXFLOAT
//
layer3.addAnimation(animation3, forKey: nil)

 如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

  • iOS如何將圖片裁剪成圓形

    iOS如何將圖片裁剪成圓形

    這篇文章主要為大家詳細(xì)介紹了iOS如何將圖片裁剪成圓形,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • iOS獲取圖片區(qū)域主色的方法

    iOS獲取圖片區(qū)域主色的方法

    這篇文章主要為大家詳細(xì)介紹了iOS獲取圖片區(qū)域主色的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • iOS實(shí)現(xiàn)百度地圖定位簽到功能

    iOS實(shí)現(xiàn)百度地圖定位簽到功能

    這篇文章主要給大家介紹了iOS實(shí)現(xiàn)百度地圖定位簽到功能的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • IOS生成與讀取二維碼名片

    IOS生成與讀取二維碼名片

    這篇文章主要為大家介紹了IOS生成與讀取二維碼名片的方法,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Swift 進(jìn)階 —— map 和 flatMap的使用

    Swift 進(jìn)階 —— map 和 flatMap的使用

    這篇文章主要介紹了Swift map和flatMap的相關(guān)資料,幫助大家更好的理解和使用Swift,感興趣的朋友可以了解下
    2020-09-09
  • IOS 開(kāi)發(fā)之swift中手勢(shì)的實(shí)例詳解

    IOS 開(kāi)發(fā)之swift中手勢(shì)的實(shí)例詳解

    這篇文章主要介紹了IOS 開(kāi)發(fā)之swift中手勢(shì)的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文大家能掌握IOS手勢(shì)的使用方法,需要的朋友可以參考下
    2017-09-09
  • iOS中震動(dòng)反饋(UIFeedbackGenerator)與系統(tǒng)震動(dòng)詳解

    iOS中震動(dòng)反饋(UIFeedbackGenerator)與系統(tǒng)震動(dòng)詳解

    最近要做一個(gè)項(xiàng)目,需要持續(xù)響鈴并振動(dòng),所以就有了這篇文章,下面這篇文章主要給大家介紹了關(guān)于iOS中震動(dòng)反饋(UIFeedbackGenerator)與系統(tǒng)震動(dòng)的相關(guān)資料,需要的朋友可以參考下
    2018-08-08
  • IOS中(Xcode) DEBUG模式(RELEASE模式)控制NSLog輸出,NSLog輸出方式

    IOS中(Xcode) DEBUG模式(RELEASE模式)控制NSLog輸出,NSLog輸出方式

    這篇文章主要介紹了IOS中(Xcode) DEBUG模式(RELEASE模式)控制NSLog輸出,NSLog輸出方式的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • iOS開(kāi)發(fā)學(xué)習(xí)之監(jiān)測(cè)程序的崩潰次數(shù)詳解

    iOS開(kāi)發(fā)學(xué)習(xí)之監(jiān)測(cè)程序的崩潰次數(shù)詳解

    iOS開(kāi)發(fā)中遇到程序崩潰是很正常的事情,下面這篇文章主要給大家介紹了關(guān)于iOS如何監(jiān)測(cè)程序崩潰次數(shù)的相關(guān)資料,文中通過(guò)詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面跟著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-07-07
  • iOS逆向教程之動(dòng)態(tài)調(diào)試詳解

    iOS逆向教程之動(dòng)態(tài)調(diào)試詳解

    這篇文章主要給大家介紹了關(guān)于iOS逆向教程之動(dòng)態(tài)調(diào)試的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-06-06

最新評(píng)論

余江县| 黑水县| 都江堰市| 伊金霍洛旗| 平阴县| 旬邑县| 内丘县| 恩施市| 镇赉县| 咸阳市| 油尖旺区| 即墨市| 兴国县| 太仆寺旗| 义马市| 饶阳县| 饶河县| 开封县| 安塞县| 景洪市| 连州市| 全州县| 怀集县| 土默特右旗| 青冈县| 岱山县| 阳朔县| 太康县| 伊川县| 广饶县| 阳信县| 伊吾县| 松滋市| 石河子市| 张家港市| 太康县| 永丰县| 双牌县| 曲阳县| 昆明市| 申扎县|