cglayer

Why does my view jump when setting the layer anchorPoint in an animation block?

自闭症网瘾萝莉.ら 提交于 2019-12-06 13:59:48
I have a UIPanGestureRecognizer attached to a view in my iOS app. I copied the code from the Touches sample app for the pan handler. When the gesture starts, my code: Records the original anchor point and center. Changes the anchor point and center to be around the user's fingers, like so: CGPoint locationInView = [gestureRecognizer locationInView:target]; CGPoint locationInSuperview = [gestureRecognizer locationInView:target.superview]; target.layer.anchorPoint = CGPointMake( locationInView.x / target.bounds.size.width, locationInView.y / target.bounds.size.height ); target.center =

Optimize Core Graphics animated drawing (iPhone)

浪子不回头ぞ 提交于 2019-12-05 02:18:04
问题 I have a loop that fires a function 30 times per second. The function changes the position of a couple of points that I use to animate. I draw lines through all the points, meaning that the lines will change 30 times per second. I draw these lines to a CGLayer, which then is drawn to a UIView in the drawRect: method. I do this because I understand that performance is improved when drawing offscreen. However, it seems that the CGLayer saves all actual lines instead of drawn pixels, since even

Optimize Core Graphics animated drawing (iPhone)

落爺英雄遲暮 提交于 2019-12-03 20:17:10
I have a loop that fires a function 30 times per second. The function changes the position of a couple of points that I use to animate. I draw lines through all the points, meaning that the lines will change 30 times per second. I draw these lines to a CGLayer, which then is drawn to a UIView in the drawRect: method. I do this because I understand that performance is improved when drawing offscreen. However, it seems that the CGLayer saves all actual lines instead of drawn pixels, since even if I clear it, the program runs slower and slower over time when more lines are drawn. I'm asking for

iOS: How do I support Retina Display with CGLayer?

拥有回忆 提交于 2019-12-03 01:04:51
问题 I'm drawing a graph on a CALayer in its delegate method drawLayer:inContext: . Now I want to support Retina Display, as the graph looks blurry on the latest devices. For the parts that I draw directly on the graphics context passed by the CALayer, I could nicely draw in high resolution by setting the CALayer's contentScale property as follows. if ([myLayer respondsToSelector:@selector(setContentsScale:)]) { myLayer.contentsScale = [[UIScreen mainScreen] scale]; } But for the parts that I use

Memory management in Coregraphics (iOS)

我怕爱的太早我们不能终老 提交于 2019-12-02 11:04:45
问题 I am working on a drawing application, I am using CGlayers for drawing, So I open my canvas for drawing on click of a button, I am using UIBezierPath and then converting it to CGPath in touchesMoved below and then using it to draw -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (ctr == 4) { m_touchMoved = true; self.currentPath = [[DrawingPath alloc] init]; [self.currentPath setPathColor:self.lineColor]; self.currentPath.pathWidth = [NSString stringWithFormat:@"%f",self

CGLayerRef in NSValue - when to call retain() or release()?

混江龙づ霸主 提交于 2019-12-02 08:25:58
I am caching some graphics onto CGLayers and then storing them in NSValue objects using @encode (so as to store them in an array). I just wanted to make sure that I handle the retain/release correctly... I cache the graphics and store them in the array something like this: // Create an NSMutableArray "newCache" CGLayerRef drawingLayer = CGLayerCreateWithContext(context, bounds.size, NULL); CGContextRef drawingContext = CGLayerGetContext(drawingLayer); // Do some drawing... [newCache addObject:[NSValue valueWithBytes:&drawingLayer objCType:@encode(CGLayerRef)]]; CGLayerRelease(drawingLayer); //

Memory management in Coregraphics (iOS)

 ̄綄美尐妖づ 提交于 2019-12-02 03:23:40
I am working on a drawing application, I am using CGlayers for drawing, So I open my canvas for drawing on click of a button, I am using UIBezierPath and then converting it to CGPath in touchesMoved below and then using it to draw -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (ctr == 4) { m_touchMoved = true; self.currentPath = [[DrawingPath alloc] init]; [self.currentPath setPathColor:self.lineColor]; self.currentPath.pathWidth = [NSString stringWithFormat:@"%f",self.lineWidth]; pts[3] = midPoint(pts[2], pts[4]);// move the endpoint to the middle of the line joining the

undo redo issues with CGLayer

a 夏天 提交于 2019-11-28 13:08:00
I am working with unod redo operations on CgLayer, I have tried some code, but not able to get it working, dont know , where I am getting wrong, below is my code, which i have written this is my drawRect function - (void)drawRect:(CGRect)rect { m_backgroundImage = [UIImage imageNamed:@"bridge.jpg"]; CGPoint drawingTargetPoint = CGPointMake(0,0); [m_backgroundImage drawAtPoint:drawingTargetPoint]; switch(drawStep) { case DRAW: { CGContextRef context = UIGraphicsGetCurrentContext(); if(myLayerRef == nil) { myLayerRef = CGLayerCreateWithContext(context, self.bounds.size, NULL); }

What's the difference and compatibility of CGLayer and CALayer?

天涯浪子 提交于 2019-11-28 03:15:20
I'm confusing CGLayer and CALayer . They look similar, so why are there separate implementations? What's the difference between, and compatibility of, CGLayer and CALayer ? Joe Blow They are completely different, and not compatible. To be absolutely clear: it is strictly a coincidence that the word "layer" is used in both names ; they are completely unrelated . CGLayers are a "special" "high performance" thingy. You could consider them "like bitmaps, but better." Apple sat down and said "We're sick of people using bitmaps, let's make something better!" :-) Indeed, you only work with CGLayers

Doing Undo and Redo with Cglayer Drawing

随声附和 提交于 2019-11-27 16:20:21
I am working with a drawing app, I am using CGlayers for drawing. On touches ended, I get image out of the layer and store it in a Array, which I use to undo operation. My touches ended function -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"Touches ended"); UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextDrawLayerInRect(context, self.bounds, self.drawingLayer); m_curImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [m_undoArray addObject: m_curImage]; }