iOS 6 view hierarchy nightmare

2019-04-29 12:30发布

问题:

I have an app in the app store with nearly 5-star rating, but when iOS 6 came out, some of the views in in the app's main view hierarchy started blinking. This happens on the app that was in the store (I removed it when iOS6 came out) as well as in the simulator.

I've spent about 14 hours, trying 100 things, to debug this in Xcode, but can't get any traction on it. Subviews disappear and reappear like there's a gremlin randomly setting the visible property off and on for each of them up to 10 times per second, in between longer periods where everything is normal.

The main interface is a dial that the user can rotate, where I use 3d transforms on a layer to rotate it. The only pattern I've found is that 3 of the 4 disappearing subviews vanish together, as if locked as one, when the dial is rotated to certain discrete positions.

The 4th disappearing subview should be a static image and it's blinking on and off with no discernible pattern.

I'd love any thoughts, tips as to how I can debug this. It's not a memory warning, and executing additional [setNeedsToDisplay] seems to have no effect. I am starting to think Apple broke something in iOS6, but I can't find anyone else talking about these issues.


Here is a breakdown of the main view's hierarchy of subviews and CALayers:

  1. My hierarchy contains 2 base CALayers that are fine.
  2. Above that are a very large custom UIView (uses drawRect) and a large UIImageVIew that blink off together, always, when the bottom one is rotated to certain positions. Only the bottom one is being rotated.
  3. Above that is a custom text drawing UIView that does not blink off.
  4. Above that is a small red pin graphic UIImageView that blinks off at the exact same time as the above 2 views. This is a vanilla UIImageView; no transforms or subsclass or custom drawing code! And yet it still has the same blinking.
  5. Above that is an invisible UIButton that seems to work all the time.
  6. Above that is a UIImageView that is a small graphic that blinks off and on constantly, unrelated to the rotation-based blinking of the other 3 "linked" layers (I say linked because they like to disappear all together).

回答1:

Try manually setting your view layers z-property to ensure the hierarchy is what you need.



回答2:

(This isn't really an answer, it's a reply to The Rat's answer, but I don't have the reputation points to comment yet)

Yes, explicitly setting zPositions seems to fix it, and yes it's weird. I also ran into this issue and blogged about it here: iOS 6 Rendering Bug: 3D-Rotation Causes Layers to Render Without Respect for View Hierarchy. It seems to be a rendering bug introduced in iOS 6. The blog has a link to the Open Radar version of the bug I filed with Apple, as well as a sample project you can run to see the bug and the zPosition fix.