iosobjective-cxcodexcode6liveview

Live View does not rotate self in Interface Builder


I have been applying Live Views on a project I have that builds most of it's UI drawn with beziers and thus far it has been nothing but magic to finally see the application come alive in Interface Builder after working so long it seeing nothing but a black screen all of the time.

There's a part where I draw a line with a hand pointing to the start. After I add all the elements I rotate the view to an offset and I rotate the hand with the same amount in the other direction to keep it pointing straight. This always worked fine when running the app so this code works.

When I added IB_DESIGNABLE I noticed the hand was missing, but I could correct that by using the bundle trick. The hand is rotated with the correct amount. But the view itself is not.

This is the relevant code:

- (void)drawRect:(CGRect)rect
{
    // ....lots of drawing code.....

    float totalRotationRadians = M_PI * 2 * -.12;
    self.transform = CGAffineTransformMakeRotation(totalRotationRadians);
    self.hand.transform = CGAffineTransformMakeRotation(-totalRotationRadians);
}

This is what it looks like in Interface Builder:

Live Rendering in Interface Builder

This is what it looks like when I run it:

When I run it on the Simulator

There are some slight differences because some things get scaled depending on the size of the View it's in but that's how it's supposed to work. Only the lack of rotation is really off.


Solution

  • I am encountering various comments on the internet about people not being able to rotate, plus a blog post that I cannot find anymore. They all tell that CALayer rotations do not work as for now in Live Views.

    I guess we'll have to wait