How to rotate UIView using transform?

风格不统一 提交于 2019-12-23 15:08:27

问题


I have a UIView which I am trying to transform (rotate) using the pitch value you can get from coremotion attitude. I am using transform however I am not sure my code is correct as the UIView is not doing anything.

This is my code its being called several times per second.

- (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;
}

I am not sure how to set this part (pitch + M_PI_2, 1, 0, 0) to make the pitch affect my square UIView so it would I guess stay level as you tilt the phone back and forth.


回答1:


It should be layer's transform property of UIView

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



回答2:


This will work

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


来源:https://stackoverflow.com/questions/23443802/how-to-rotate-uiview-using-transform

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