ARKit基礎(chǔ)(五)——AR動(dòng)畫效果

上一節(jié)中已經(jīng)接觸過(guò)CABasicAnimation

-(void)cupMoveTo:(SCNVector3) position{
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation"];
    animation.toValue=[NSValue valueWithSCNVector3:position];
    animation.removedOnCompletion=NO;
    animation.duration=2;
    animation.fillMode=kCAFillModeForwards;
    [cupNode addAnimation:animation forKey:@"move"];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        cupNode.position= position;
    });
}

這里再介紹一個(gè)旋轉(zhuǎn)動(dòng)畫效果

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    // NSLog(@"touch the screen");
    UITouch *touch=[touches anyObject];
    CGPoint point = [touch locationInView:[touch view]];
    
    SCNVector3 planePos=[self worldPositionFromScreenPosition:point];
    
    if (planePos.x*planePos.x+planePos.y*planePos.y+planePos.z*planePos.z>3) {
        [shipNode removeFromParentNode];
        
        if (shipNode==nil) {
            SCNScene *scene = [SCNScene sceneNamed:@"art.scnassets/lamp/lamp.scn"];
            shipNode = scene.rootNode.childNodes[0];
            shipNode.position = SCNVector3Make(0, 0, -1.5);
        }
        
        SCNNode *node1 = [[SCNNode alloc] init];
        node1.position = planePos;
        [sceneView.scene.rootNode addChildNode:node1];
        [node1 addChildNode:shipNode];
        
        CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"rotation"];
        rotationAnimation.duration = 15;
        rotationAnimation.toValue = [NSValue valueWithSCNVector4:SCNVector4Make(0, 1, 0, M_PI * 2)];
        rotationAnimation.repeatCount = FLT_MAX;
      
        [node1 addAnimation:moonRotationAnimation forKey:@"rotation around"];
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 在iOS中隨處都可以看到絢麗的動(dòng)畫效果,實(shí)現(xiàn)這些動(dòng)畫的過(guò)程并不復(fù)雜,今天將帶大家一窺ios動(dòng)畫全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,690評(píng)論 6 30
  • 在iOS中隨處都可以看到絢麗的動(dòng)畫效果,實(shí)現(xiàn)這些動(dòng)畫的過(guò)程并不復(fù)雜,今天將帶大家一窺iOS動(dòng)畫全貌。在這里你可以看...
    F麥子閱讀 5,268評(píng)論 5 13
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,983評(píng)論 25 709
  • 男: ①日支力強(qiáng)為用神,財(cái)星純正、旺盛。 ②身旺,見食、傷生財(cái)。 ③身旺,見厚財(cái)生官。 ④身寒,日支見火。 ⑤身燥...
    運(yùn)安閣主閱讀 178評(píng)論 0 0
  • “他叫什么呢?他到底叫什么呢?” 其實(shí)夏令營(yíng)中有許許多多的老師來(lái)給我們上課,來(lái)教會(huì)我...
    沈遷閱讀 300評(píng)論 0 0

友情鏈接更多精彩內(nèi)容