2012-11-14 61 views
1

我试图在其中心旋转UILabel,但当它旋转时,它会改变其位置。它并不拘泥于其中心。我正在使用以下代码来旋转它:在其中心旋转UILabel

float fromAngle = atan2(m_locationBegan.y-lblText.center.y, m_locationBegan.x-lblText.center.x); 
//float toAngle = atan2(_location.y-lblText.center.y, _location.x-lblText.center.x); 
float toAngle = atan2(_location.y-lblText.center.y+5, _location.x-lblText.center.x+5); 
float newAngle = wrapd(m_currentAngle + (toAngle - fromAngle), 0, 2*3.14); 

CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle); 
lblText.transform = cgaRotate; 

int oneInFifty = (newAngle*50)/(2*3.14); 

NSLog(@"%@",[NSString stringWithFormat:@"fromAngle: %f toAngle: %f Angle: %f 1in50: %i",fromAngle, toAngle, newAngle, oneInFifty]); 

有人可以帮助我阻止中心从中移动吗?

回答

0

看看这个blog post

实施例:(label = UILabel

// UIView's transform property is a CGAffineTransform. 
[UIView beginAnimations:nil context:NULL]; // arguments are optional 
view.transform = CGAffineTransformMakeRotation(M_PI_2); 
[UIView commitAnimations]; 

// CALayer's transform property is a CATransform3D. 
// rotate around a vector (x, y, z) = (0, 0, 1) where positive Z points 
// out of the device's screen. 

label.layer.transform = CATransform3DMakeRotation(M_PI_2, 0, 0, 1);