如何使用transform旋转UIView?

时间:2014-05-03 11:26:43

标签: ios iphone uiview transform core-motion

我有UIView我试图使用你可以从coremotion态度得到的音高值来转换(旋转)。我正在使用转换但是我不确定我的代码是否正确,因为UIView没有做任何事情。

这是我的代码,它每秒被调用几次。

- (void)setLabelValueRoll:(double)roll pitch:(double)pitch yaw:(double)yaw
{
    self.yLabel.text = [NSString stringWithFormat:@"pitch: %f", pitch];


    CATransform3D transform;
    transform = CATransform3DMakeRotation(pitch + M_PI_2, 1, 0, 0);
    self.wapaA.layer.sublayerTransform = transform;
}

我不确定如何设置此部分(音高+ M_PI_2,1,0,0)以使音高影响我的方格UIView所以我猜它会保持水平为你来回倾斜手机。

2 个答案:

答案 0 :(得分:2)

应该是layer's transform property

UIView
wapaA.layer.transform = CATransform3DMakeRotation(pitch + M_PI_2, 1, 0, 0); 

答案 1 :(得分:0)

这将有效

float degrees = 20; //the value in degrees
view.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);