Enabling layer-backed views? - calayer

I keep seeing that in order to get transformations around the center point of a CALayer, you need to turn on layer-backing? I can't figure out how to do it though! Please help...

I am surprised you didn't see that in the docs. Just send the layer the wantsLayer message. Or if you prefer dot syntax just do layer.wantsLayer = YES;

Related

UIPageViewController and transparent page backs

Can anyone help with a problem with UIPageViewController giving transparent page backs?
I have a project displaying mock-ups of old newspapers. I am setting double sided to true and have slightly blurred and mirrored images for the page backs.
One prototype version is okay and looks like this as a page turns:
However, an updated version with different background looks like this:
As you can see, the curled page back is now completely transparent.
I think the code is the same in each case although the UIView hierarchy is different.
Can anyone help me out by explaining what might be the cause?
Many thanks!
This problem appears to be due to the fact that I had a sublayertransform in place that was not the Identity matrix. Resetting before using UIPageViewController fixes it.
let noPerspective = CATransform3DIdentity
self.view.layer.sublayerTransform = self.noPerspective
This clearly interfered with UIPageViewController's animation.

Swift - UIIMageView(Aspect Fill) and automatic row height

I'm trying to figure out how can I solve a problem.
Basically I have a Dynamic TableView, with dynamic Images(Different Sizes).
I want to set always a fixed width:320 for the UIImage and use the Mode: Aspect Fill(Without Clip Subviews), the image maintains the width and set the height dynamically based on my width, but the problem is, my image cover up everything else, like labels, buttons and edges of my cells, I tried to use auto-layout with constraints to reposition these other components(labels,buttons,etc), but not worked.
I don't know if just using the Interface Builder I can solve this behavior or I need to check/calculate some information programmatically.
Any ideas are welcome.
Thanks Team!
Due to lacking of your code as example, I can just suggest you use a swift library from GitHub called Toucan. Toucan is a Swift library that provides a clean, quick API for processing images. And it solve my image problem smoothly.
You should be able to solve this in Interface Builder.
I usually am always able to accomplish my desired layout using constraints and priorities. Only in cases with dynamic type it gets difficult.
I don't know the layout of your cell. It would be helpful if you would post a screenshot of your cell and indicate where the overlap occurs.

Convert screen coordinate to window coordinate in Cocoa?

I've seen this question asked multiple times here, and I tried some answers, but it doesn't seem to work for me.
NSPoint pnt = [[self window] convertScreenToBase:[NSEvent mouseLocation]];
I'm using above code to do my conversion, but I get same coordinates for pnt.x and pnt.y no matter where mouse location is.
I noticed that this method is deprecated, but it should still work I guess, right?
Does anyone have any good suggestion on how I can do this conversion?
Any kind of help is highly appreciated!
You should use [window mouseLocationOutsideOfEventStream] instead.

How to Rotate a CALayer-backed NSView subclass

I have a custom NSView subclass that I want to animate with Core Animation. I am already (without CA) setting the position and rotation of these views with NSView's setFrameOrigin and setFrameRotation methods. However, no matter what I do, once I add a layer backing to the views I can't get them to rotate.
I've tried using NSView's setFrameRotation and setFrameCenterRotation methods. The latter moves the view a bit, but doesn't rotate its content. The former has no effect. Applying a CATransform3D created by CATransform3DRotate to the view's layer also has no effect.
I'm feeling a little dumb asking this question, because it seems like something that should be easy, but for the life of me I can't figure out how to make it work. Someone, please make me smack my forehead at how easy it was. :)
Turns out that the superview needed to be layer-backed as well in order for this to work. Making that change fixed it.

Core Animation - Sheet-like Window Sliding

How difficult would it be to use core animation to make an NSView slide in an out of view like a sheet? Generally speaking, what would be involved in accomplishing this? I've been reading through the CA documentation, but it's been hard for me to pinpoint which parts are relevant to what I want to do since I have no experience with the framework.
Any tips at all would be much appreciated.
Thanks.
Since you're talking of a NSView, you're probably using Cocoa's animation support, not CA directly. In this case, you just need to set the view's frame through the view's animator object:
[theView setFrame:offscreenFrame];
[[theView animator] setFrame:finalFrame];
Unfortunately, Cocoa view animation interacts badly with the more advanced features of CA, like setting an easing. You might have more luck using NSViewAnimation instead, which is not Core Animation-backed and allows for a little more flexibility.

Resources