calayer

How can I animate manually on the iPhone?

I've got a very simplistic "game" set up on the iPhone. Things move around, rotate, you can interact with them, etc. In the simulator, it runs fine, but on the device it gets around 0.25 FPS, and it's so slow that it doesn't have time to recognize touches, apparently. This was originally just using a UIView with an array of Items each...

CALayer flickers when drawing a path

I am using a CALayer to display a path via drawLayer:inContext delegate method, which resides in the view controller of the view that the layer belongs to. Each time the user moves their finger on the screen the path is updated and the layer is redrawn. However, the drawing doesn't keep up with the touches: there is always a slight lag i...

Tips for reducing Core Animation memory usage

So here's the situation: I have a CALayer that is the size of my screen, and I'm setting the contents property to a 2 Mb JPEG that's roughly 3500 x 2000 pixels in size with a resolution of 240ppi. I'd expect there to be a slight overhead involved in using the CALayer, but my sample application (which only does exactly what's above) sho...

How to get touch event on a CALayer?

ok - I'm new to the iPhone SDK. Right now I'm programming with CALayers which I really like a lot- not as expensive as UIViews, and a lot less code than OpenGL ES sprites. I have this question- is it possible to get a touch event on a CALayer? I understand how to get a touch event on a UIView with -(void)touchesBegan:(NSSet *)touches...

how do you copy an CALayer?

How to you make an NSArray full of multiple instances of a CALayer (all with the same frame, contents etc)? Background: CALayer takes a bit of overhead to create, so I would like to create a number of CALayers (all sharing the same properties) in the init method of a class (to be used later on in that class.) ...

How should I do multiple animations on the iPhone?

I'd like to animate multiple pieces for a game and i'd like to have those pieces move in different directions so my current method of animating an entire view will no longer work. I'm wondering what is the best practice for animating multiple items at once. (Note i'm rendering in 2d so i'm not currently interested in 3d soltuions.) Th...

How do you optimize UIColor on the iPhone?

I'm creating a simple color picker controlled by a custom slider type control. I'm passing a float value from my slider to a UIColor constructor method and updating the background color of a CALayer as the value changes. It runs really smooth in the simulator, but I get a lot of flickering when running on the device. Is this just bec...

Why can't I access the visibleRect Property of an CALayer in iPhone SDK?

I am having trouble doing this: CALayer *myLayer = myUIImageView.layer; //works, no error from compiler CGRect visRect = myLayer.visibleRect; //fat error, see below The Error I get is: error: request for member 'visibleRect' in something not a structure or union but the documentation says: visibleRect Returns the visi...

How do I get the visibleRect Rectangle out of an UIImageView?

Actually that should work, but it doesnt: CALayer *myLayer = [myUIImageView layer]; CGRect visRect = [myLayer visibleRect]; I get an "invalid initializer" error, although my view is loaded definitely since in the next few lines I obtain the frame from the view and move the view around. But under no circumstances I can obtain that visi...

Why does the visibleRect method of CALayer give me always the same width for my UIImageView even if I move it half out of the screen?

I get the visibleRect from an UIImageView inside a method, that is called several times to move that view to the right. As soon as it goes partly out of the screen, I expect that the visibleRect becomes smaller. But it does not. -(IBAction)moveToRight:(id)sender { CGRect frameRect = myUIImageView.frame; //that's an image I use in ba...

Is there a reason I can't initialize a CALayer outside a UIView class?

I have been trying to us CALayers as "sprites" in an iPhone application I'm working on. From what I have been reading, that seems like the correct thing to do here. When I setup the layer inside a UIView class I am able to get the layer to show up on the screen: NSLog(@"GameView initWithCoder"); NSString* imagePath = [[NSBundle mai...

How can I subclass CALayer to return a pre-styled layer?

How do you subclass CALayer so that you return a layer with styling properties already set? So that: MyCustomLayer *layer = [MyCustomLayer layer]; would create a layer with these properties; layer.backgroundColor = sweetBackgroundColor.CGColor; layer.borderColor = sweetBorderColor.CGColor; layer.borderWidth = 2.0; layer.cornerRadiu...

Performance issues scaling multiple CALayers

I have two CALayer subclasses, each with their own drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx delegate. They are both simple layers (some single color shapes drawn with CG paths), but I need to scale about 12 instances simultaneously, and I'm having some issues with frame rates. I marked all of the layers as opaque to try to ...

CALayer coordinate system

Hi, I'm quite new to Cocoa, but would like to know how to change a CALayer's coordinate system. I read the article Layer Geometry and Transforms from the Core Animation Programming Guide, but still need some practical advice. The default coordinate system has (0,0) at the lower left corner. I would like to change this to the center of t...

Most efficent way to create a CALayer with an image in it?

I am wondering what the most efficient way is to make a CALayer with an image in it. I know you can load a UIImage and then call [image CGImage] but is this the best way of going about it? As far as I can tell from Apple's documentation this is the only way you can do it. ...

Displaying PDFs on iPhone - CALayers?

I'm having a huge headache trying to figure this out. I'm trying to display a single page from a pdf file (the only one that is). This pdf page is a map that I need to zoom in and out with pinching, etc... I am doing this with CATileLayers (each tile being 256x256, but can set it to a bigger size). It does the job but REALLY slowly. What...

How to keep model & controller separate from a CALayer based UI?

I'm trying to re-implement an old Reversi board game I wrote with a bit more of a snazzy UI. I've looked at Jens Alfke's GeekGameBoard code for inspiration, and CALayers looks like the way to go for implementing the UI. However, there is no clean separation of model and view in the GeekGameBoard code; the model is the view, which makes ...

How can I get only a partial rectangle from a CALayer ?

I'm getting a "snapshot" of an UITextView as CGImage, but the problem is that the content of the UITextView is very long ( about ~110k contentSize.height ) and when I render the UITextView layer in to the context the memory usage becomes ~130MB which causes the application to crash when run on a device. Here is the code. viewref is an i...

UIView animation vs CALayers on iPhone

I'm struggling with conceptualizing animations with a CALayer as opposed to UIView's own animation methods. Throw "Core Animation" into this and, well, maybe someone can articulate these concepts from a high level so I can better visualize what's happening and why I'd want to migrate UIView animations (which I'm quite familiar with now) ...

How do I save state with CALayers?

I have a simple iphone application that paints blocks using a subclass of CALayer and am trying to find the best way to save state or persist the currently created layers. I tried using Brad Larson's answer from this previous question on storing custom objects in the NSUserDefaults, which worked for persisting my subclass of CALayer, bu...