2010-12-21 46 views
0

縮放我使用此代碼從一個特定的點從特定點

CGPoint getCenterPointForRect(CGRect inRect) 
{ 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    return CGPointMake((screenRect.size.height-inRect.origin.x)/2,(screenRect.size.width-inRect.origin.y)/2); 
} 

-(void) startAnimation 
{ 
    CGPoint centerPoint = getCenterPointForRect(self.view.frame); 
    self.view.transform = CGAffineTransformMakeTranslation(centerPoint.x, centerPoint.y); 
    self.view.transform = CGAffineTransformScale(self.view.transform , 0.001, 0.001); 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:kTransitionDuration]; 
    self.view.transform = CGAffineTransformIdentity; 
    [UIView commitAnimations]; 
} 

放大它不工作。什麼是從特定點進行縮放的正確方法。

回答

0

我認爲,如果我正確診斷你的問題,你要縮放動畫,其視圖開始很小,在一個點,然後縮放和移動到完全像你想要的屏幕的中心,但它的起點不正確?

首先,意見周圍擴展它們的中心。所以,如果你拿出的翻譯,從而減少了代碼,你必須:

self.view.transform = CGAffineTransformMakeScale(0.001, 0.001); 

而且你的觀點最終佔據整個屏幕,然後它會保持在屏幕的正中,有點一點點好像它還有很長的路要走,並且你直接朝着它前進。

假如你,而不是希望它長,並移動到屏幕的距離(X,Y)的中心,那麼你需要更多的東西一樣:

CGPoint locationToZoomFrom = ... populated by you somehow ...; 
CGPoint vectorFromCentreToPoint = CGPointMake(
       locationToZoomFrom.x - self.view.center.x, 
       locationToZoomFrom.y - self.view.center.y); 

self.view.transform = CGAffineTransformMakeTranslation(vectorFromCentreToPoint.x, vectorFromCentreToPoint.y); 
self.view.transform = CGAffineTransformScale(self.view.transform , 0.001, 0.001); 

凡locationToZoomFrom將視圖的初始中心它的正常中心按照其框架將成爲目的地。