• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Animation layout behavior during live window resize
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Animation layout behavior during live window resize


  • Subject: Re: Core Animation layout behavior during live window resize
  • From: Troy Stephens <email@hidden>
  • Date: Wed, 6 Feb 2008 16:34:00 -0800

Hi Ben,

On Feb 6, 2008, at 12:12 PM, Ben Kazez wrote:
Hi,

I have a layer-backed view that resizes to fit the available space in the window. During live window resizes, I'd like the layers to resize with no animation.

For the "pure" layer-backed view case, where you're just setting wantsLayer=YES on various views and leaving it to AppKit automatically create and manage the backing layers, AppKit does automatically suppress the default animations that would otherwise occur for those layers during window live resize.


I gather you've inserted some additional layers of your own into the AppKit-generated layer tree, and are using a CAConstraintLayoutManager to position those layers? (I wouldn't recommend setting up a layout manager that tries to position the auto-generated view backing layers, as you'll just end up fighting against AppKit's attempts to keep them in sync with the corresponding views.)

Assuming that's the case, you've got a reasonable, well-targeted approach in (1), but it sounds like you're hitting a known CATransaction crash bug (which I can readily reproduce by trying what you describe).

Until such time as a fix for that bug makes it out, you should be able to work around the problem by omitting the transaction begin/commit as below:

@implementation MyLayoutManager
- (void)layoutSublayersOfLayer:(CALayer *)layer {
id oldValue = [[CATransaction valueForKey: forKey:kCATransactionDisableActions
[CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions];
[super layoutSublayersOfLayer:layer];
[CATransaction setValue:[NSNumber numberWithBool:NO] forKey:kCATransactionDisableActions];
}
@end


Or, to be a bit more pedantically correct about the saving and restoring of the enclosing DisableActions state:

@implementation MyLayoutManager
- (void)layoutSublayersOfLayer:(CALayer *)layer {
id oldValue = [[CATransaction valueForKey: forKey:kCATransactionDisableActions] retain];
[CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions];
[super layoutSublayersOfLayer:layer];
[CATransaction setValue:oldValue] forKey:kCATransactionDisableActions];
[oldValue release];
}
@end


This works for me. Let me know if it doesn't solve your problem for some reason.

Troy

1. I get a crash when I begin a transaction and use kCATransactionDisableActions within the layout manager's - layoutSublayersOfLayer method.

2. Disabling actions within a transaction from viewWillStartLiveResize/viewDidEndLiveResize seems to disable the animation, but I can't be sure, because the view content isn't updated properly: The background color of the root layer is not redrawn, and the layers do not reposition themselves.

3. To fix #2, I tried setAutoresizesSubviews:YES and laying out the root layer (-layoutIfNeeded or -setNeedsLayout) from - resizeSubviewsWithOldSize, but this had no effect.

4. As a proof of concept, I tried unsetting the root layer from the view (setLayer:nil) and setting wantsLayer:NO, and then drawing a plain black background in -drawRect during live resizes. (My thinking was that eventually I'd render the root layer contents to an image and scale the image to provide a low-resolution preview during live window resizes.) However, this caused crazy drawing artifacts and window flickering.

I'm surely missing something obvious. What's the recommended way of doing this?

Ben
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


--
Troy Stephens
Cocoa Frameworks
Apple, Inc.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Core Animation layout behavior during live window resize
      • From: Ben Kazez <email@hidden>
References: 
 >Core Animation layout behavior during live window resize (From: Ben Kazez <email@hidden>)

  • Prev by Date: Re: Autocomplete word as you are typing
  • Next by Date: Re: Core Data, NSURLProtocol and Threads - A Case of Missing Managed Objects
  • Previous by thread: Core Animation layout behavior during live window resize
  • Next by thread: Re: Core Animation layout behavior during live window resize
  • Index(es):
    • Date
    • Thread