旋转UILabel在其中心 [英] Rotating UILabel at its center

查看:100
本文介绍了旋转UILabel在其中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在其中心旋转 UILabel ,但是当它旋转时,它会改变它的位置。它并不坚持其中心。我正在使用以下代码来旋转它:

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?

推荐答案

看看这个博客文章

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

这篇关于旋转UILabel在其中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆