layer 實現(xiàn) (直接修改layer位置,控件會跟著移動)
- layer 主要屬性 直接修改屬性,默認有動畫
- 圓角 cornerRadius self.button.layer.cornerRadius = 50; 減去陰影效果 layer . masksToBounds = YES
- contents 內(nèi)容 layer.contents = (__brige id _Nullabel) ( image.CGImage ) 也可作為背景設(shè)置
- 陰影 shadowOpacity shadowOffset shadowRadius
- 邊框 borderWidth 有動畫 向內(nèi)縮進 borderColor
- transform屬性
- 旋轉(zhuǎn) CATransform3DRotate (self.layer.transform , M_PI , X ,Y ,Z )
- 縮放 CATransform3DScale (self.layer.transform , M_PI , X ,Y ,Z )
- 平移 translate
- position 和 anchorPoint
- position 相對于父layer來說的 位置
- anchorPoint 錨點 定位點 相對于自己說的 取值范圍 0~1 默認 (0.5 , 0.5 ) 自己的高度 寬度 都乘以 0.5 確定layer 對于父layer的 相對值
核心動畫 CorAnimation (對layer添加動畫 UIView 不會跟著動畫走動)
- 結(jié)構(gòu)繼承
- CABasicAnimation 基本動畫
- fromValue
- toValue
- byValue
- CAKeyframeAnimation 關(guān)鍵幀動畫
- CAAnimationGroup 組動畫 group .animations addAnimation
- CATransition 轉(zhuǎn)場動畫
- type 主動畫
- subType 子動畫
- CABasicAnimation 基本動畫
- 結(jié)構(gòu)圖
screenshot.png
實現(xiàn)步驟
- 實現(xiàn)步驟 ( 一定先 設(shè)置屬性 再添加 否則 后面的屬性無效)
- 創(chuàng)建動畫對象 anim = [CABasicAnimation aimationWithKeyPath : @“position.y “ ] bounds.size(縮放) transform.rotation.z(旋轉(zhuǎn))
- 設(shè)置屬性 anim.fromValue = @200 anim. toValue = @500
- 添加到對應(yīng)的layer上 [ self.layer addAnimation : aim forKey nil ] Key: 刪除的時候需要用到
- 讓位置停留 (動畫結(jié)束會默認 刪除)
- 設(shè)置代理 (不需要協(xié)議)
- animationDidStart
- animationDidStop