2012-01-09 10 views
5

İşte UIview 30px'i aşağı yukarı y = 10'a taşımak için kullandığım kod budur ancak bu animasyon çalışmaz. Bu benim CAKeyframeAnimation'ı yaratma ilk denememdir, bu yüzden herkes doğru yazmam için bana yardımcı olabilir. Ayrıca, neslimin orijinal yerine geri dönmemesini, ancak animasyonun bittiği yerde kalmasını istiyorum.CAKeyframeanimation, yol boyunca UIView'i hareket ettirin

CGMutablePathRef thePath = CGPathCreateMutable(); 
    CGPathAddRect(thePath, NULL, CGRectMake(self.logo.frame.origin.x, self.logo.frame.origin.y, self.logo.frame.size.width, self.logo.frame.size.height)); 
    CGPathAddRect(thePath, NULL, CGRectMake(self.logo.frame.origin.x, self.logo.frame.origin.y-30, self.logo.frame.size.width, self.logo.frame.size.height)); 
    CGPathAddRect(thePath, NULL, CGRectMake(self.logo.frame.origin.x, 100, self.logo.frame.size.width, self.logo.frame.size.height)); 


    CAKeyframeAnimation* AniLoc = [CAKeyframeAnimation animationWithKeyPath:@"frame"]; 
    AniLoc.path = thePath; 
    AniLoc.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
    AniLoc.keyTimes= [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], 
         [NSNumber numberWithFloat:0.3f], 
         [NSNumber numberWithFloat:1.0f],nil]; 
    AniLoc.duration = 2.0; 

    CFRelease(thePath); 

    [self.logo.layer addAnimation:AniLoc forKey:nil]; 
+0

Hangi şekilde "çalışmıyor"? – jrturton

+0

animasyon hiçbir şey hareket etmiyor –

cevap

1

Yöntemin neden çalışmadığından emin değilim, ancak başka bir çözüm önerebilirim. yerine çerçeveyi sürüş, sen UIView taşımak için pozisyon anahtarını değiştirebilirsiniz: Bu size yardımcı olur umarım

CGMutablePathRef thePath = CGPathCreateMutable(); 
    CGPathMoveToPoint(thePath, NULL, self.logo.frame.origin.x, self.logo.frame.origin.y); // initial point, notice the function 
    CGPathAddLineToPoint(thePath, NULL, self.logo.frame.origin.x - 30, self.logo.frame.origin.y); 
    CGPathAddLineToPoint(thePath, NULL, 100, self.logo.frame.origin.y); 

    CAKeyframeAnimation* AniLoc = [CAKeyframeAnimation animationWithKeyPath:@"position"]; // notice key change 

    // rest is the same 
    AniLoc.path = thePath; 
    AniLoc.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
    AniLoc.keyTimes= [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], 
         [NSNumber numberWithFloat:0.3f], 
         [NSNumber numberWithFloat:1.0f],nil]; 
    AniLoc.duration = 2.0; 

    CFRelease(thePath); 

    [self.logo.layer addAnimation:AniLoc forKey:nil]; 

.

+1

Çalışmıyor çünkü çerçeve türetilmiş bir özelliktir. Çerçeveyi canlandırmaya gereksiniminiz varsa, sınırları ve konumu animasyonlandırın. – alecail

İlgili konular