I have some CALayers in a layer hosted view. Each of these layers has additional layers to hold (1) a close button, and (2) a resize handle. These additional 'control' layers are added as sublayers to the parent layer.
Currently, when I zoom the workspace in which these layers reside, everything scales -- including these control layers. However, I would like to prevent these control layers from scaling.
Is there a way to override the behaviour of having scale transforms being applied to all sublayers, without having to override the drawInContext: method for each control layer (presumably to invert any existing scale transform -- assuming this is possible) and without having to manually send each of these control layers a setNeedsDisplay: with every zoom?
I found this thread which discusses doing something similar but the discussion goes in the direction of CATiledLayers which is not what I'm looking for here.
Redrawing CALayer subclass when super layer is scaled
Also, this post asks a somewhat related question but the responses do not apply to my situation, since I cannot overlay the controls -- they must be part of the layer hierarchy.
How do I keep a CALayer, sublayer of a CATiledLayer, from changing it's scale after a zoom?
I ended up solving this problem by overriding the layoutSublayers method of my custom CALayers, obtaining the accumulated scale transform of the layer hierarchy, and applying the inverse transform to the control sublayers.
Related
In one of the WWDC 2014 talks on the new Yosemite UI, it says to avoid the use of NSVisualEffectView in masked layers. Unfortunately my view's layer does have a shape mask, and as a result the visual effect view in it has an ugly jagged edge effect:
However I know it must be somehow possible to create a masked visual effect view, partly due to 2 reasons:
The image mask property on NSVisualEffectView produces a smooth, anti-alised mask (but requires an unmasked background behind it, and not just an unmasked parent view)
NSPopover and NSMenu seem to be able to achieve a smooth mask that changes with dimensions:
Although it is doubtable as to wether or not they use NSVisualEffectView, and not a custom blurred view.
Is there any way I can achieve this smooth mask that doesn't rely on a mask image but rather a path or shape layer?
I was trying to achieve this with a NSWindow view a while back and I came across this awesome library: https://www.cocoacontrols.com/controls/waythedarkside
It allows you to add a light or dark blur to your view/background. I think this is what you are looking for :)
I'm looking for a solution to make a video from a CoreAnimation animation.
If I recursively enumerate the sublayers of my root CALayer presentation layer, is there a risk that the values(position, transform, opacity..) keep on changing while I'm a reading the properties in the (presentation) tree ? Or is the presentation layer like a deep copy of the CALayer hierarchy ?
The presentation layer is a deep copy of the model layer, with all the active animations applied. It's not actually the literal presentation tree that's used to render to screen, it's just an approximation.
I have a large image managed with CATiledLayer (like the Large Image Downsizing iOS sample code).
I had a drawing view (UIView overrided with drawing methods) on it but when I zoom a lot, I get the following message and my view disappeared..
-[<CALayer: 0xb253aa0> display]: Ignoring bogus layer size (25504.578125, 15940.361328)
Is there a way to avoid this ?
Sounds like the levelsOfDetail and levelsOfDetailBias you are setting are allowing for more zoom than the tiled layer should allow given the max layer size allowable for the layer. Try changing those to lessen how much the user can zoom.
Here is a great article explaining some of the undocumented behavior of CATiledLayer.
I'm trying to write a fairly simple animation using Core Animation to simulate a book cover being opened. The book cover is an image, and I'm applying the animations to its layer object.
As well as animating a rotation around the y axis (The the anchorPoint property set of the left of the screen), I need to scale the right hand edge of the image up so it appears to "get closer" to the user and create the illusion of depth. Flipboard, for example, does this scaling really well.
I can't find any way of scaling an image like this, so only one edge is scaled and the image ends up nonrectangular.
All help appreciated with this one!
CoreAnimation, by default, "flattens" its 3D hierarchy into a 2D world at z=0. This causes perspective and the like to not work properly. You need to host your layer in a CATransformLayer, which will render its sublayers as a true 3D layer hierarchy.
I've got my layer hosted workspace working so that using CATiledLayers for hundreds of images works nicely when the workspace is zoomed out substantially. All the images use lower resolution representations, and my application is much more responsive when panning and zooming large numbers of images.
However, within my application I also provide the user the ability to resize layers with a resize handle. Before I converted image layers to use CATiledLayers I was doing layer resizes by manipulating the bounds of the image layer according to the resize delta (mouse drag), and it worked well. But now with CATiledLayers in place, this is causing CATiledLayers to get confused when I mix resizing of layers through bounds manipulation and zooming/unzooming the workspace through scale transforms.
Specifically, if I resize a CATiledLayer to half the width/height size (1/4 the area), the image inside it will suddenly scale to a further 1/2 the resized frame leaving 3/4 of the frame empty. This seems to be exactly when the inner CATiledLayer logic gets invoked to provide a lower resolution image representation. It works fine if I don't touch the resize handler and just zoom/unzoom the workspace.
Is there a way to make zooming/resizing play nice together with CATiledLayers, or am I going to have to convert my layer resize logic to use scale transforms instead of bounds manipulations?
I ended up solving this by converting my layer resize logic to use scale transforms by overriding the setBounds: method for my custom image layer class to scale it's containing CATiledLayer, and repositioning accordingly. Also it is important to make sure the CATiledLayer's autoresizingMask is set to kCALayerNotSizable since we are handling resizes manually in setBounds:.
Note: be sure to call the superclass's implementation of setBounds:.