1

I have a UITableViewCell subclass with backgroundView set to my own UIView object. This UIView object contains three CALayer layers. I implemented - (void)layoutSubviews where I update all my CALayer layers. The problem is autorotation.

When I rotate from landscape to portrait mode there's this cosmetic issue:

During the animation, all my CALayer layers are as narrow as in portrait mode.

It seems that this guy is right:

When layoutSubviews gets called during an orientation change, the view's bounds are already set to what they will be at the conclusion of the rotation.

Source: How to achieve smooth animation when using single-step rotation / How do I get the new frame size at the start of rotation?

So, where should I update my layers to achieve proper autorotation? The view is already rotating them, so I suppose there's no need to do any custom animations, just adjust the size. Right?

Community
  • 1
  • 1
Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118

1 Answers1

2

Figured it out:

  1. subclass CALayer + add sublayers into it
  2. implement resizing of sublayers in CALayer's - (void)layoutSublayers method
  3. subclass UIView + override + (Class)layerClass in it:

    + (Class)layerClass {
        return [SubclassedCALayer class];
    }
    
  4. set the subclassed UIView as backgroundView of UITableViewCell

Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
  • I think I'm having the same issue as you and I followed these instructions, but I still have the same issue. The rotation animation works fine from portrait to landscape. The table cells all stretch out, getting wider. However, when you go back to portrait, the background of the cell snaps back to the portrait width immediately while the rest of the cell shrinks back to the smaller width. Is there any chance you can share some of your code to see if there is something subtle that I am missing? Thanks. – Greg G May 13 '14 at 16:13
  • @GregG I'm sorry but I don't have that code anymore. – Rudolf Adamkovič May 14 '14 at 09:20