core-graphics

Force clockwise/anticlockwise rotation for a CABasicAnimation of a UIImageView

你说的曾经没有我的故事 提交于 2019-12-04 19:54:27
问题 I'm animating a pendulum which swings from 0 degrees to max 200 degrees and then back again. The problem is that if the pendulum goes over 180 degrees, it returns to 0 by the shortest route which is to continue clockwise. And I'd like it to go anticlockwise. Here's my code: ('right' is a boolean which is TRUE when the pendulum is swinging from left to right) - (void)swingPendulum { CABasicAnimation *rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform

What is the difference between closing the bezier path using closePath function and closing it manually?

时光毁灭记忆、已成空白 提交于 2019-12-04 19:42:10
问题 I am trying to make a rectangle using UIBezierPath . I adopted two different ways to draw it. Also, I increased the stroke width to 25 px. First method : Using closePath UIBezierPath *bpath = [UIBezierPath bezierPath]; [bpath moveToPoint:CGPointMake(x, y)]; [bpath addLineToPoint:CGPointMake(x + w, y)]; [bpath addLineToPoint:CGPointMake(x + w, y + h)]; [bpath addLineToPoint:CGPointMake(x, y + h)]; [bpath closePath]; Output: Second method : Closing the path manually UIBezierPath *bpath =

Converting a CGLayer to a *transparent* UIImage and PNG file in CoreGraphics iphone

折月煮酒 提交于 2019-12-04 19:33:48
I've been making a simple painting app for the iphone. I'm trying to convert the drawn image to a transparent PNG (I don't want a white background). I'd also like to get a UIImage representation to use in a UIImageView. Currently, I respond to touch events and draw paths to a CGLayer which is then drawn to my views context. I have access to both the CGLayer as well as the view itself. Currently, I output my view to an image using: UIGraphicsBeginImageContext(drawingView.bounds.size); [drawingView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage =

CAGradientLayer and scrollViewTexturedBackgroundColor

女生的网名这么多〃 提交于 2019-12-04 19:05:57
I'm trying to use CAGradientLayer to fade foreground controls against the background textured view. So in a nutshell, I have a view with the bg color as scrollViewTexturedBackgroundColor. I have a view on top of that, whose contents I'd like to fade at the border into the background view's color. CAGradientLayer* gradient = [CAGradientLayer layer]; gradient.frame = self->scrollableCanvas.bounds; gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor scrollViewTexturedBackgroundColor] CGColor], (id)[[UIColor scrollViewTexturedBackgroundColor] CGColor], nil]; [gradient setStartPoint

Free Drawing On UIImage Embedded in UIScrollView

半腔热情 提交于 2019-12-04 18:49:56
I am working on project that involves drawing freehand on a UIImage inside a UIScrollView. Everything works fine with the drawing at default zoom, however if I adjust the zoom of the UIScrollView and try drawing again, it starts to distort the image by shrinking it and making the image appear blurry. It also pushes the images to the far left-right of the screen. I have tried using different scaling options to no avail. Here is the image at normal scale with some drawing in it. Here is the image after zooming and drawing for a few seconds Here is the relevant code (methods are declared in the

Convert MKCircle Radius to CoreGraphics Arc Radius

不想你离开。 提交于 2019-12-04 18:45:48
How can I convert an MKCircle's radius (in meters) into a value I can use to draw a circle using core graphics in an MKOverlayPathView subclass? In the following code the radius is hardcoded to 50 but I need it to reflect the radius of the MKCircle. For the position I use MKMapPointForCoordinate() to convert the MKCircle's coordinate to an MKMapPoint, then convert the MKMapPoint to a point using MKOverlayPathView's pointForMapPoint:. But how can I convert the MKCircle's radius into a relative distance? MKCircle *circle = [self circleForLocation:location]; CGPoint relativePoint = [self

iOS CoreImage Edge detection

こ雲淡風輕ζ 提交于 2019-12-04 17:48:52
I am writing an iOS as and I need to be able to do edge detection in the image. I actually want something similar to Photoshop's trace contour. Since I basically need to get the simplest set of lines to work with.. Thing is I cannot seem to figure out how to do it and frankly I have 0 interest in OpenCV since I spent 5 hours today trying to get any of the 10 or so zips of it I downloaded to compile, in any way shape or form. So I was hoping maybe some one could point me the right way to do it with what's built in to the os.. or maybe an example If haven't used it myself, but are you looking

How to move image in circle swift

╄→尐↘猪︶ㄣ 提交于 2019-12-04 17:37:17
Can anybody explain to me how I can create the path of circle and move an image around it. What I need: let circlePath = UIBezierPath(arcCenter: CGPoint(x: 100,y: 100), radius: CGFloat(20), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true) I discovered how do the path of circle, but the rest I don't know to do. I'm new to iOS development. And, I need this action begin when I open the page. Check this code, the objectToMove is an UIView from storyBoard to test, here I am using your path code but I had added more radius import UIKit class ViewController: UIViewController {

Adding a QuadCurve to UIBezierPath

情到浓时终转凉″ 提交于 2019-12-04 17:16:54
I am doing a drawing app and I am trying to smooth the line which I draw with finger.For this purpose I am using "quadCurveToPoint" function. But, I am not getting it right. Below is my code: - (void) drawRect:(CGRect)rect { [path stroke]; } - (id) initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) self.multipleTouchEnabled = NO; path = [UIBezierPath bezierPath]; path.lineWidth = IS_IPAD? 2.0f : 1.0f; return self; } - (void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event { UITouch *touch = [touches anyObject]; m_previousPoint1 = [touch locationInView:self]; m

Why use functions like CGRectMake?

我的未来我决定 提交于 2019-12-04 15:56:37
问题 I'm curious why functions like CGRectMake and CGPointMake exist and are widely used. when, instead, you can do: (CGRect){{x, y}, {width, height}} surely this is more efficient (though I'm guessing not by much) as there is no function call? Also you can set the origin and size like: (CGRect){origin, size} and as a mixture: (CGRect){origin, {width, height}} What is the reason for not using this, and preferring the Make functions? 回答1: It isn't more efficient, actually. The CGRectMake function