MapKit lines and polygons - iphone

I have a map and line (poly-line) on it. I'm trying to make a smooth polygon around this line. The problem I'm facing is how to create that polygon look smooth with rounded ends. any suggestions/solutions?
I've tried to draw another line over existing one with different thickness, but it doesn't work well with zooming...

In MKOverlayPathView which is a superclass of MKPolylineView there is a property called lineCap. Set it to
kCGLineCapRound
check here:
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKOverlayPathView_class/Reference/Reference.html
Hope it helps.

Related

How to draw a circle using arcs in createjs?

How to draw an arc in createJS. I have gone through arcTo function but its not what i want. I want to be able to draw several arcs which when put together resembles a circle.
for Ex: I want to be able to draw a circle using 8 arcs. not able to do it using ArcTo function. Please some one suggest me a way to do it.
The arcTo function draws directly from the specified point. The arc() function is what you are looking for.
Here is a quick sample that draws random segments.
http://jsfiddle.net/lannymcnie/nJKHk/
shape.graphics.arc(0,0,50,startAngle,endAngle);
here is another sample with random color fills.
http://jsfiddle.net/lannymcnie/nJKHk/1/

iPhone: How to animate a CAShape line whose path is determined by user input

I'm attempting to replicate the "worm" that is sometimes displayed on political debates to represent the audiences opinion on how well a candidate answered a question. It's basically a line that animates along the x axis to represent time, up and down the y axis to represent opinion.
I see that I can do this animation by
Creating a UIBezierPath and use its moveToPoint/addLineToPoint methods with a predefined set of coordinates.
Create a CAShapeLayer and set its path property to the above UIBezierPath.
Create a CABasicAnimation and add it to the CAShapeLayer.
This is all fine but I need for the line to be affected in real time by user input (tapping a button to move the line up or down), meaning that in step one above I cannot have a set of pre-defined coordinates. The line should move horizontally unless it receives input from the user to make it also move vertically.
So my question is how would I go about this? Can I still somehow use the method I described in the bullet points above with some modification or do I have to use a different means?
Many thanks for any advice!
[edit]
I just had a thought, this may work but be a little inefficient and I'm not sure if the created path would be very short i.e. not the full path from the starting point instead just the currently drawn part of the path?! What if I did the following:
create two variables, lastPoint and currentPoint;
repetitively call a draw method that does the following
[path moveToPoint: lastPoint];
[path addLineToPoint: currentPoint];
lastPoint = currentPoint;
currentPoint = [self calculateNewPointFromUserInput];
repeat;
Two points will be very short for you, you can take an array of user's touch events and then draw last 10-15 points from the array. I think this will serve your purpose.

clear part of UIImage

I've been doing some research on online for a project I'm doing but so far haven't been able to quite get it working. I want to be able to slide my finger over a UIImage and delete part of it, kind of like an eraser. I'm able to draw lines on the screen but can't figure out how to do this. Any help would be greatly appreciated.
Can you mask the image and when you draw on it, it adds the lines to the mask (in white, rest of mask is black) and then it should make those spots transparent
http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
There are two parts to this problem-
a) Determining the curve along which the finger was moved
b) Drawing the curve (which is really a combination of short lines) with the white color
For part (a), have a look at UIPanGestureRecognizer. Using the touchesBegan: & touchesMoved methods, you will be notified every time the finger moves even the smallest distance, and the source and destination co-ordinates, say (x1, y1) & (x2, y2).
Part (b), As you know how to draw a line, now you need to draw a line from the source to the destination with the line's width (thickness) equal to the finger's. For that you can set the line's width using CGContextSetLineWidth.

UIBezierPath Gives Sharp Edges

When I'm using a UIBezierPath to draw where the user is touching if the user moves to fast sometimes I get really hard points like the tip of a triangle. Any clue what might be causing this? Or how I can fix it?
I am capturing the points using touchesBegan/Moved/Ended and placing them into an NSArray of UIBezierPaths.
Despite the name, UIBezierPath doesn't just draw curves. In fact, by default it won't - presumably you're simply passing the coordinates returned by touchesBegan etc, into the addLineToPoint method.
Instead of simply passing all the touch coordinates directly into a UIBezierPath you should first interpolate them to avoid these sharp lines that occur when you rapidly move your finger across the screen. This is not too difficult, although does require some knowledge of how bezier curves work and spline interpolation.
If you are looking for a slightly easier way out, there are a couple of open source libraries that will do this for you, like this one: http://cocoacontrols.com/platforms/ios/controls/smooth-line-view

how to draw line with animation?

I have implemented game application in which i want to draw line between two object.I have drawn line between two objects.But i want to draw with animation.can u advise me which animation i have to used between two points.
Edit:My excatly question is that:
Suppose there is two point like start point(100,100) and endpoint(300,300).I can draw line between this two point but i want to draw line with animation.I mean i can see line start from start point to end point with 2 secon duration.please help me about this question.
+1 for Brad's answer—it'll work—but it looks like you can accomplish the same thing in a more straightforward fashion by animating the strokeStart and strokeEnd properties on CAPathLayer.
See http://oleb.net/blog/2010/12/animating-drawing-of-cgpath-with-cashapelayer/
If you're looking to animate the extension of a line from point A to between points A and B, my recommendation would be to use a CAShapeLayer for this. CAShapeLayer lets you animate the interpolation between two paths with the same number of control points. For an example of this in action, see Joe Ricioppo's post on the subject.
In your case, you'd start with a path that has two control points, both the same point, and use as the final path one that has a control point at the start of the line and one at the end. The line will then animate out as if it were being drawn in a single brush stroke.