4

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183
  • If wapaA is the UIView, then just applying wapaA.transform should work – ZeMoon May 03 '14 at 11:35
  • If i do that I get a warning **Property access result unused - getters should not be used for side effects** nore dose it work unfortunatly. – HurkNburkS May 03 '14 at 11:49

2 Answers2

2

It should be layer's transform property of UIView

wapaA.layer.transform = CATransform3DMakeRotation(pitch + M_PI_2, 1, 0, 0); 
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • great! that worked.. thanks for that I ended up changing the calculation to get the effect i want **(pitch + M_PI_2, 0, 0, 1)** – HurkNburkS May 03 '14 at 12:24
0

This will work

float degrees = 20; //the value in degrees
view.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);
Shaheen Ghiassy
  • 7,397
  • 3
  • 40
  • 40