core-graphics

How to draw a smooth circle with CAShapeLayer and UIBezierPath?

我们两清 提交于 2019-12-17 17:23:48
问题 I am attempting to draw a stroked circle by using a CAShapeLayer and setting a circular path on it. However, this method is consistently less accurate when rendered to the screen than using borderRadius or drawing the path in a CGContextRef directly. Here are the results of all three methods: Notice that the third is poorly rendered, especially inside the stroke on the top and bottom. I have set the contentsScale property to [UIScreen mainScreen].scale . Here is my drawing code for these

Get Slightly Lighter and Darker Color from UIColor

情到浓时终转凉″ 提交于 2019-12-17 17:18:21
问题 I was looking to be able to turn any UIColor into a gradient. The way I am intending to do this is by using Core Graphics to draw a gradient. What I am trying to do is to get a color, lets say: [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]; and get a UIColor which is a few shades darker and a few shades lighter. Does anyone know how to do this? Thank you. 回答1: - (UIColor *)lighterColorForColor:(UIColor *)c { CGFloat r, g, b, a; if ([c getRed:&r green:&g blue:&b alpha:&a]) return

Where and how to __bridge

社会主义新天地 提交于 2019-12-17 15:17:22
问题 I need some advice on __bridge -ing in iOS. Hopefully the SSCCE 1 below will explain the problem better than I can in words, but I need to know how I can convert a void* to an NSMutableArray* ; which __bridge variation should be used (See comment in code). Reading about the different bridges, I deduced that I would need __bridge_transfer but then I receive an EXC_BAD_ACCESS on addObject: Ultimately, I'd like to have an array of the CGPoints in the CGPath after CGPathApply has been called.

Crop a CAShapeLayer retrieving the external path

时光毁灭记忆、已成空白 提交于 2019-12-17 10:35:16
问题 I am trying to crop a layer with other, but, instead of creating a mask (B) and crop the layer (A) getting a cropped layer A with the shape of B, I want to get a layer with shape A and a 'hole' created by cropping with layer B. ************* ***Layer A*** * Layer A * ************* * ***** * **** ***** * * B * * -> **** ***** Layer A without shape B * ***** * **** ***** * * ************* ************* ************* How can I get the cropped layer A? 回答1: You have to create a mask that covers

Get path to trace out a character in an iOS UIFont

只愿长相守 提交于 2019-12-17 08:59:10
问题 Suppose I have a custom font "Foo" that I'm using in my iOS App. I've added it to my project, plist, etc. and I'm able to render UILabel s and such with it just fine. Now, if I want to find out a sequence of points that would "trace out" the letter 'P' in that font, how would I get that sequence of points? For example, suppose I wanted to use a CGPath to draw the letter 'P' slowly like a plotter would ... I just need a sequence of CGPoints in an array that if drawn as a path would draw a 'P'.

Tweening / Interpolating between two CGPaths / UIBeziers

試著忘記壹切 提交于 2019-12-17 06:23:10
问题 I have a CAShapeLayer which contains a CGPath. Using the built-in animation of iOS I can easily morph this path into another one using an animation: CABasicAnimation *morph = [CABasicAnimation animationWithKeyPath:@"path"]; morph.fromValue = (id)myLayer.path; mayLayer.path = [self getNewPath]; morph.toValue = (id)myLayer.path; morph.duration = 0.3; [myLayer addAnimation:morph forKey:nil]; That works perfectly. However, I'd now like to morph gradually between these paths during a drag

One step affine transform for rotation around a point?

旧街凉风 提交于 2019-12-17 04:25:11
问题 How can I make a Core Graphics affine transform for rotation around a point x,y of angle a, using only a single call to CGAffineTransformMake() plus math.h trig functions such as sin(), cos(), etc., and no other CG calls. Other answers here seem to be about using multiple stacked transforms or multi-step transforms to move, rotate and move, using multiple Core Graphics calls. Those answers do not meet my specific requirements. 回答1: A rotation of angle a around the point (x,y) corresponds to

Can I use CGAffineTransformMakeRotation to rotate a view more than 360 degrees?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 03:56:12
问题 I'm writing an iPhone app, and I've got an image which I'ld like to have swirl outwards. Currently my code looks like this (wrapped in a beginAnimations/commitAnimations block): scale = CGAffineTransformScale(CGAffineTransformIdentity, 5.0f, 5.0f); swirl = CGAffineTransformRotate(scale, M_PI); [player setTransform:swirl]; [player setAlpha:0.0f]; But I find that if I try to change the angle of the rotation to, say, 4*M_PI, it doesn't rotate at all. Is it possible to get a 720˚ rotation using

Draw segments from a circle or donut

*爱你&永不变心* 提交于 2019-12-17 02:53:05
问题 I've been trying to figure out a way to draw segments as illustrated in the following image: I'd like to: draw the segment include gradients include shadows animate the drawing from 0 to n angle I've been attempting to do this with CGContextAddArc and similar calls but not getting very far. Can anyone help ? 回答1: There are many parts to your question. Getting the path Creating the path for such a segment shouldn't be too hard. There are two arcs and two straight lines. I've previously

Resize UIImage with aspect ratio?

时光总嘲笑我的痴心妄想 提交于 2019-12-17 02:27:08
问题 I'm using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:kCGBlendModePlusDarker alpha:1]; UIImage *tmpValue = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); Which is working great, as long as the aspect ratio of the image matches that of the new resized image. I'd like to modify this so that it keeps the correct aspect ratio and just