Search Results

Search found 12 results on 1 pages for 'cashapelayer'.

Page 1/1 | 1 

  • CAShapeLayer slowing down interface rotation

    - by MrMage
    Hi, I am trying to move some custom drawing code from a view into a CAShapeLayer, which then get added as a sublayer to the original view's CALayer. This also works well, but when rotating the device, the animation starts to stutter, e.g. you just see the frame in the original orientation and then the final orientation, with at most one frame in between - not smooth at all. Slide-in and slide-out animations of the corresponding UIViewController are a bit jerky, too (but not that much). All the CAShapeLayer has in its path is one CGPathAddRect, it is set to be opaque, its opacity is 1.0f and the fillColor is set to opaque blue. When drawing the path directly in the views drawRect method, however, the animation is smooth. So I suppose it has something to do with the CAShapeLayer being animated during the rotation. Could you tell me how to either get rid of those jerkiness or just hide the CAShapeLayer when animating? Getting back to just draw CGPaths directly is not an option to me because I rely on the ability of CAShapeLayer to animate its path (it is not animated in my tries with rotating the view). /update: this also happens when the rotating UIViewControllers view contains a view with a subclass of CAGradientLayer as its layerClass (e.g. a view with a gradient layer as background). Cheers MrMage

    Read the article

  • How to animate an non-closed path with CAShapeLayer?

    - by mystify
    On GitHub you can find an example for CAShapeLayer which animates an path. It animates a pentagon turning into a star. First: This works only in the iPhone simulator. OS 3.0 on the device shows serious bugs with this code. But I can't find anything wrong in there. However, I tried to animate an path which is not closed. To put it simply: A few straight lines. Is there anything special I must do to get this work properly on the device? - (void)loadView { UIView *appView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; appView.backgroundColor = [UIColor blackColor]; self.view = appView; [appView release]; rootLayer = [CALayer layer]; rootLayer.frame = self.view.bounds; [self.view.layer addSublayer:rootLayer]; //Pentagon Path pentagonPath = CGPathCreateMutable(); CGPathMoveToPoint(pentagonPath, nil, 10.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 100.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 110.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 120.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 130.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 310.0f, 270.0f); //CGPathCloseSubpath(pentagonPath); //Star Path starPath = CGPathCreateMutable(); CGPathMoveToPoint(starPath, nil, 10.0f, 270.0f); CGPathAddLineToPoint(starPath, nil, 100.0f, 270.0f); CGPathAddLineToPoint(starPath, nil, 210.0f, 270.0f); CGPathAddLineToPoint(starPath, nil, 220.0f, 260.0f); CGPathAddLineToPoint(starPath, nil, 230.0f, 270.0f); CGPathAddLineToPoint(starPath, nil, 310.0f, 270.0f); //CGPathCloseSubpath(starPath); //Create Shape shapeLayer = [CAShapeLayer layer]; //shapeLayer.path = pentagonPath; UIColor *col = [UIColor colorWithWhite:0.9 alpha:1.0]; //shapeLayer.fillColor = col.CGColor; shapeLayer.strokeColor = col.CGColor; shapeLayer.lineWidth = 3.0f; // shapeLayer.contents = [UIImage imageNamed:@"test.png"]; shapeLayer.fillRule = kCAFillRuleEvenOdd; [rootLayer addSublayer:shapeLayer]; [self performSelector:@selector(startAnimation) withObject:nil afterDelay:1.0]; } -(void)startAnimation { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"]; animation.duration = 2.0; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.repeatCount = 1e100f; animation.autoreverses = YES; animation.fromValue = (id)pentagonPath; animation.toValue = (id)starPath; [shapeLayer addAnimation:animation forKey:@"animatePath"]; } Note this lines, where I just make straight lines with a small peak which is animated: //Pentagon Path pentagonPath = CGPathCreateMutable(); CGPathMoveToPoint(pentagonPath, nil, 10.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 100.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 110.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 120.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 130.0f, 270.0f); CGPathAddLineToPoint(pentagonPath, nil, 310.0f, 270.0f); //CGPathCloseSubpath(pentagonPath); //Star Path starPath = CGPathCreateMutable(); CGPathMoveToPoint(starPath, nil, 10.0f, 270.0f); CGPathAddLineToPoint(starPath, nil, 100.0f, 270.0f); CGPathAddLineToPoint(starPath, nil, 210.0f, 270.0f); CGPathAddLineToPoint(starPath, nil, 220.0f, 260.0f); CGPathAddLineToPoint(starPath, nil, 230.0f, 270.0f); CGPathAddLineToPoint(starPath, nil, 310.0f, 270.0f); I don't want a closed and filled path, but only simple lines with some color and thickness. The nasty thing on the device is, that the first point seems to move towards the right side of the screen for no reason. On the simulator though, it works perfectly fine. Maybe something is wrong with this setup?

    Read the article

  • change fillColor of selected CAShapeLayer

    - by Frank
    I'm trying to change the fillColor of a CAShapeLayer when the layer it's contained in is touched. I'm able to change the background color of the tapped layer like this: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CALayer *layer = [(CALayer *)self.view.layer.presentationLayer hitTest:point]; layer = layer.modelLayer; layer.backgroundColor = [UIColor blueColor].CGColor; } This turns the background of "layer" blue as expected. My problem is how do I change the color of the CAShapelayer inside "layer"? Thanks!

    Read the article

  • Animating the drawing of a line

    - by jkigel
    I'm trying to animate the drawing of a line by the following way: .h CAShapeLayer *rootLayer; CAShapeLayer *lineLayer; CGMutablePathRef path; .m path = CGPathCreateMutable(); CGPathMoveToPoint(path, nil, self.frame.size.width/2-100, 260); CGPathAddLineToPoint(path, nil, self.frame.size.width/2+100.0, 260); CGPathCloseSubpath(path); self.rootLayer = [CALayer layer]; rootLayer.frame = self.bounds; [self.layer addSublayer:rootLayer]; self.lineLayer = [CAShapeLayer layer]; [lineLayer setPath:path]; [lineLayer setFillColor:[UIColor redColor].CGColor]; [lineLayer setStrokeColor:[UIColor blueColor].CGColor]; [lineLayer setLineWidth:1.5]; [lineLayer setFillRule:kCAFillRuleNonZero]; [rootLayer addSublayer:lineLayer]; [self performSelector:@selector(startTotalLine) withObject:nil afterDelay:1.5]; - (void)startTotalLine { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"animatePath"]; [animation setDuration:3.5]; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [animation setAutoreverses:NO]; [animation setFromValue:(id)path]; [animation setToValue:(id)path]; [lineLayer addAnimation:animation forKey:@"animatePath"]; } The line had drawn before the startTotalLine method is invoked. Also, the startTotalLine method doesn't affect the line. I want it to animate the the line drawing from right to left

    Read the article

  • Blind down animation on CALayer using a mask

    - by dgjones346
    Hi there, I want to create a "blind down" effect on an image so the image "blinds down" and appears. Sort of like this JavaScript transition: http://wiki.github.com/madrobby/scriptaculous/effect-blinddown The mask is setup correctly because if I manually change it's position it hides and reveals the image behind it, but it doesn't animate! It just ends up in the animates final position and you never see it actual blind. Please help! Maybe this isn't the best way to achieve a blind down effect? // create a new layer CALayer *numberLayer = [[CALayer alloc] init]; // render the number "7" on the layer UIImage *image = [UIImage imageNamed:@"number-7.png"]; numberLayer.contents = (id) [image CGImage]; numberLayer.bounds = CGRectMake(0, 0, image.size.width, image.size.height); // width and height are 50 numberLayer.position = position; // create a new mask that is 50x50 the size of the image CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, nil, CGRectMake(0, 0, 50, 50)); [maskLayer setPath:path]; [maskLayer setFillColor:[[UIColor whiteColor] CGColor]]; [theLayer setMask:maskLayer]; [maskLayer setPosition:CGPointMake(0, 0)]; // place the mask over the image [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:3.0]; [maskLayer setPosition:CGPointMake(0, 50)]; // slide mask off the image // this should shift the blind away in an animation // but it doesn't animate [UIView commitAnimations]; [maskLayer release]; [boardLayer addSublayer:numberLayer]; [numberLayer release];

    Read the article

  • How to draw shadows that don't suck?

    - by mystify
    A CAShapeLayer uses a CGPathRef to draw it's stuff. So I have a star path, and I want a smooth drop shadow with a radius of about 15 units. Probably there is some nice functionality in some new iPhone OS versions, but I need to do it myself for a old aged version of 3.0 (which most people still use). I tried to do some REALLY nasty stuff: I created a for-loop and sequentially created like 15 of those paths, transform-scaling them step by step to become bigger. Then assigning them to a new created CAShapeLayer and decreasing it's alpha a little bit on every iteration. Not only that this scaling is mathematically incorrect and sucks (it should happen relative to the outline!), the shadow is not rounded and looks really ugly. That's why nice soft shadows have a radius. The tips of a star shouldn't appear totally sharp after a shadow size of 15 units. They should be soft like cream. But in my ugly solution they're just as s harp as the star itself, since all I do is scale the star 15 times and decrease it's alpha 15 times. Ugly. I wonder how the big guys do it? If you had an arbitrary path, and that path must throw a shadow, how does the algorithm to do that work? Probably the path would have to be expanded like 30 times, point-by-point relative to the tangent of the outline away from the filled part, and just by 0.5 units to have a nice blending. Before I re-invent the wheel, maybe someone has a handy example or link?

    Read the article

  • UIBezierPath too many paths = too slow?

    - by HHHH
    I have a loop in which I'm adding many (10000+) lines to a UIBezierPath. This seems to be fine, but once I try and render the bezierpath, my device becomes extremely slow and jerky. Is this because I've added too many lines to my path? Adding lines to UIBezierPath - simplified: (this seems fine) [path moveToPoint:CGPointZero]; for (int i = 0; i < 10000; i++ ) { [path addLineToPoint:CGPointMake(i, i)]; } Rendering BeizerPath (Suggested by Rob) - this seems slow. - (void)drawBezierAnimate:(BOOL)animate { UIBezierPath *bezierPath = path; CAShapeLayer *bezier = [[CAShapeLayer alloc] init]; bezier.path = bezierPath.CGPath; bezier.strokeColor = [UIColor blueColor].CGColor; bezier.fillColor = [UIColor clearColor].CGColor; bezier.lineWidth = 2.0; bezier.strokeStart = 0.0; bezier.strokeEnd = 1.0; [self.layer addSublayer:bezier]; if (animate) { CABasicAnimation *animateStrokeEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; animateStrokeEnd.duration = 100.0; animateStrokeEnd.fromValue = [NSNumber numberWithFloat:0.0f]; animateStrokeEnd.toValue = [NSNumber numberWithFloat:1.0f]; [bezier addAnimation:animateStrokeEnd forKey:@"strokeEndAnimation"]; } } Qs: 1) Is this because I'm adding too many paths too quickly? 2) I want to eventually draw many different lines of different colors, so I assume I would need to create multiple (10000+) UIBezierPaths - would this help or greatly slow the device as well? 3) How would I get around this? Thanks in advance for your help.

    Read the article

  • Animating a CALayer's mask size change

    - by Alexander Repty
    I have a UIView subclass which uses a CAShapeLayer mask on its CALayer. The mask uses a distinct shape, with three rounded corners and a cut out rectangle in the remaining corner. When I resize my UIView using a standard animation block, the UIView itself and its CALayer resize just fine. The mask, however, is applied instantly, which leads to some drawing issues. I've tried animating the mask's resizing using a CABasicAnimation but didn't have any luck getting the resizing animated. Can I somehow achieve an animated resizing effect on the mask? Do I need to get rid of the mask, or will I have to change something about the way I currently draw the mask (using - (void)drawInContext:(CGContextRef)ctx). Cheers, Alex

    Read the article

  • Breaking One Big Graphic of MutablePaths into CAShapeLayers

    - by StackOverFlowRider
    I have a class called GraphicView that takes a Graphic object and draws it in its drawRect method. This Graphic object is basically an array of mutablePaths that comprise an icon that I want drawn. For performance and other issues, I was thinking of taking this icon that is comprised of mutablePaths, and dividing it into a bunch of CAShapeLayers. I'm wondering is this possible? Considering the points for the mutablePaths of the icon are all interwoven together (ie the icon was initially an SVG file that I converted to code), is it possible to divide different parts of the icon into CAShapeLayers, and reassemble them all together when assigning to the views layer? If so how would it be done? If I assign them as sublayers to a CALayer or CAShapeLayer, will it understand to mesh them all together?

    Read the article

  • add animation to layer's path in cocos2d

    - by greg rock
    so i'm on cocos2d but before I was on a normal ios app and I had this code : -(void)viewDidLoad{ rootLayer = [[CALayer alloc] init]; [imageView.layer addSublayer:rootLayer]; roundPath = CGPathCreateMutable(); CGPathMoveToPoint(roundPath, nil, center.x , center.y - 35); CGPathAddArcToPoint(roundPath, nil, center.x + 35, center.y - 35, center.x + 35, center.y + 35, 35); CGPathAddArcToPoint(roundPath, nil, center.x + 35, center.y + 35, center.x - 35, center.y + 35, 35); CGPathAddArcToPoint(roundPath, nil, center.x - 35, center.y + 35, center.x - 35, center.y, 35); CGPathAddArcToPoint(roundPath, nil, center.x - 35, center.y - 35, center.x, center.y - 35, 35); CGPathCloseSubpath(roundPath); //Box Path boxPath = CGPathCreateMutable(); CGPathMoveToPoint(boxPath, nil, center.x , center.y - 35); CGPathAddArcToPoint(boxPath, nil, center.x + 35, center.y - 35, center.x + 35, center.y + 35, 4.7); CGPathAddArcToPoint(boxPath, nil, center.x + 35, center.y + 35, center.x - 35, center.y + 35, 4.7); CGPathAddArcToPoint(boxPath, nil, center.x - 35, center.y + 35, center.x - 35, center.y, 4.7); CGPathAddArcToPoint(boxPath, nil, center.x - 35, center.y - 35, center.x, center.y - 35, 4.7); CGPathCloseSubpath(boxPath); shapeLayer = [CAShapeLayer layer]; shapeLayer.path = boxPath; [rootLayer addSublayer:shapeLayer]; } -(void)startAnimation { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"]; animation.duration = 2.0; animation.repeatCount = HUGE_VALF; animation.autoreverses = YES; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.fromValue = (id)boxPath; animation.toValue = (id)roundPath; [shapeLayer addAnimation:animation forKey:@"animatePath"]; } But I didn't found a way to do the animation fromboxpath toroundpath on cocos2d, I don't know what CCAction use . Can anybody help me ? sorry for my english I'm french :/

    Read the article

1