<p id="qitwt"></p>
      1. <object id="qitwt"><strong id="qitwt"></strong></object>
        <p id="qitwt"></p>
        <li id="qitwt"></li>
        <p id="qitwt"><del id="qitwt"><xmp id="qitwt"></xmp></del></p>
        <p id="qitwt"><label id="qitwt"></label></p>
      2. <acronym id="qitwt"></acronym>
        <p id="qitwt"></p>
        免費開源的iOS開發學習平臺

        核心動畫CoreAnimation:2-動畫的實現步驟

        動畫的實現步驟

        當我們需要創建一個動畫時,通??梢园凑杖缦虏襟E進行:

        • 實例化一個CAAnimation的子類對象,例如CABasicAnimation、CAKeyframeAnimation、CATransition等;
        • 設置動畫對象的動畫屬性;
        • 添加動畫對象到一個CALayer類的對象上,并播放動畫。

        簡單示例

        我們通過一個簡單的示例,介紹一下動畫的實現步驟,該示例實現了對一個視圖對象的layer進行平移,在平移的過程中播放動畫。

        -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
            //初始化CALayer對象,并添加到控制器view的layer上
            CALayer *subLayer = [CALayer layer];
            subLayer.frame = CGRectMake(140, 100, 100, 100);
            subLayer.backgroundColor = [UIColor yellowColor].CGColor;
            subLayer.borderColor = [UIColor redColor].CGColor;
            subLayer.borderWidth = 4.0;
            subLayer.cornerRadius = 2.0;
            [self.view.layer addSublayer:subLayer];
        
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                //1-實例化CABasicAnimation對象
                CABasicAnimation *animation = [CABasicAnimation animation];
                //2-設置動畫屬性
                animation.keyPath = @"position";
                animation.toValue = [NSValue valueWithCGPoint:CGPointMake(290, 150)];
                animation.duration = 2.0;
                //3-添加動畫對象到一個CALayer類的對象上,播放動畫
                 [subLayer addAnimation:animation forKey:nil];
            });
        }
        

        示例代碼

        https://github.com/99ios/14.4.2


        青青草国产成人久久_jizzjizz日本护士高清_亚洲 另类 国产 另类_99久久免费精品色老
        <p id="qitwt"></p>
          1. <object id="qitwt"><strong id="qitwt"></strong></object>
            <p id="qitwt"></p>
            <li id="qitwt"></li>
            <p id="qitwt"><del id="qitwt"><xmp id="qitwt"></xmp></del></p>
            <p id="qitwt"><label id="qitwt"></label></p>
          2. <acronym id="qitwt"></acronym>
            <p id="qitwt"></p>