2012-10-05 43 views
0

的旋轉點,我試圖用旋轉的動畫我幀:如何改變框架

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationCurve:UIViewAnimationCurveLinear]; 

self.toNextButton.transform = CGAffineTransformMakeRotation(180.0f); 

[UIView commitAnimations]; 

但這個代碼繞着他的中心框架。我怎樣才能在框架右下角旋轉?

+0

你可以嘗試設置'toNextButton'的中心點在廈門國際銀行給它的右下角可能,這將解決您的問題:) –

+1

檢查這個帖子:http://stackoverflow.com/questions/6160519 /如何旋轉一個任意點的對象 –

回答

2

之前,你需要改變view.layer的anchorPoints

-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view 
{ 

    CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y); 
    CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y); 

    newPoint = CGPointApplyAffineTransform(newPoint, view.transform); 
    oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform); 

    CGPoint position = view.layer.position; 

    position.x -= oldPoint.x; 
    position.x += newPoint.x; 

    position.y -= oldPoint.y; 
    position.y += newPoint.y; 

    view.layer.position = position; 
    view.layer.anchorPoint = anchorPoint; 
} 

,你應該實現這樣的。

[self setAnchorPoint:CGPointMake(1,1)]; 
UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationCurve:UIViewAnimationCurveLinear]; 

self.toNextButton.transform = CGAffineTransformMakeRotation(180.0f); 

[UIView commitAnimations]; 
+0

'anchorPoint'它一定是右下角的按鈕?在這種情況下,我的按鈕正在消失.. – RomanHouse

+0

我已經實現了這個代碼,它工作正常。 –

+0

非常感謝,現在我明白它是如何工作的:) – RomanHouse

2

添加以下行啓動動畫

self.toNextButton.layer.anchorPoint = // right bottom point on the button