Rotating UILabel at its center

元气小坏坏 提交于 2019-12-13 12:19:52

问题


I am trying to rotate a UILabel at its center, but when it rotates it changes its position. It doesn't stick to its center. I am using following code to rotate it:

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]);

Can someone please help me in stopping the center moving from it?


回答1:


Take a look at this blog post.

Example: (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);


来源:https://stackoverflow.com/questions/13377504/rotating-uilabel-at-its-center

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!