iOS - how to draw a line of custom shapes - ios

I am porting my android app over to iOS using Swift.
With android, I am able to draw a line made up of a series of custom shapes, defined as path objects, by using the PathDashPathEffect object.
m_StampPath = new Path();
m_StampPath.moveTo(...);
m_StampPath.cubicTo(...);
m_StampPath.cubicTo(...);
...
m_StampPath.close();
m_WavyLine = new PathDashPathEffect(m_StampPath, fStampOffset, 0.0f, PathDashPathEffect.Style.MORPH);
// this is a Paint object
pt.setPathEffect(m_WavyLine);
pt.setStyle(Paint.Style.STROKE);
LinePath = new Path();
LinePath.moveTo(...);
LinePath.lineTo(...);
canvas.drawPath(LinePath, pt);
How can I achieve the same thing by using swift in iOS ?
I have not found anything as yet, but perhaps I am looking in the wrong place.

Related

Bezier circles getting cropped on the mac

My app runs on Mac and iOS. (two code bases with lots of shared code).
I have a piece of common code that converts a shape to a NSBezierPath/UIBezierPath.
The code is identical between the two - except for the NS*/UI*.
I then create a CAShapeLayer and set the path for the layer to the Bezier path.
That layer is added to a set of layers in the view. Again... common code between iOS and Mac.
One type of shape is a simple circle.
To create this I call:
path.AddArc(point.CGPoint(), width/2, 0, (float)(2 * Math.PI), true);
When I add this to my layer... I get a clipped circle, but only on the Mac. On iOS this works perfectly.
I tried switching to AppendPathWithOvalInRect:
path.AppendPathWithOvalInRect(rect);
That provides a slightly different clip direction:
The layer construction is very simple, and identical between Mac and iOS.
var layer = new CAShapeLayer();
layer.LineWidth = 0f;
layer.FillColor = color;
layer.StrokeColor = color;
layer.Path = GetBezier().CGPath();
objectLayer.AddSubLayer(layer);
I can see no evidence of masks or clipping on any other object. Just all my circles, and only on the Mac.
I've also included below an example of a number of simple objects - lines, fat lines, circles. You can see that all circles have this weird clipping.
Any thoughts on what I might be missing here?
Thx for your help...
I have a solution.
It turns out I was missing a ClosePath().
Interestingly... iOS does not need the ClosePath call.
On the Mac, the following calls do need a ClosePath call:
AddArc, FromOvalInRect, AppendPathWithArc.
The following call did not seem to need a ClosePath call:
FromRoundedRect
because I could use that to draw a perfect circle.

Xamarin.Forms.Maps iOS Padding

I am having trouble finding a solution for my problem. I am looking to set the padding for the Xamarin Forms Map (Mapkit/MKMapView) on iOS (Custom Renderer).
For Android it can be set in the custom renderer with NativeMap.SetPadding(10,200,10,10) but I cannot find a way to do it in iOS.
The problem I am trying to solve is that the compass on the map appears on the top right corner of the map (iOS) and since I do have my own controls on the top of the map, the compass is not accessible.
On android setting the padding pushes the compass down below my controls and solves the issue.
I’d appreciate any suggestion on how to solve it for iOS
MapKit.MKMapView
You can create your own MKCompassButton and alter its X/Y position (via its Frame) on the map.
var compass = MKCompassButton.FromMapView(mkMapViewInstance);
compass.CompassVisibility = MKFeatureVisibility.Visible;
compass.Frame = new CGRect( new CGPoint(25,25), compass.Frame.Size);
re: https://developer.apple.com/documentation/mapkit/mkcompassbutton?language=objc
Google.Maps.MapView (iOS)
You can add padding around the edges of the map using the GMSMapView.padding property. The map will continue to fill the entire container, but text and control positioning, map gestures, and camera movements will behave as if it has been placed in a smaller space. This results in the following changes:
myGMSMapViewInstace.Padding = new UIEdgeInsets(100.0f, 100.0f, 100.0f, 100.0f);

Making opaque layer in OpenGL ES 2.0 on iOS.

I'm working on a simple 3D application with OpenGL ES 2 on iOS.
I just followed steps in "OpenGL ES Programming Guide for iOS" in Apple Developer Site.
I wanted make the OpenGL View entirely opaque for better performance as suggested in the document. So, I did as below.
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = TRUE;
And, I ran the application with the Core Animation instrument. Then, I turned on 'Color Blended Layers' in Debug Options in Core Animation instrument.
Then, the entire screen became reddish which means the entire view was being blended. I tested another example OpenGL apps from Apple, but they were all greenish with the instrument.
The document dosen't say anything about this except making the layer opaque just like I did.
What else could there be possible cause for this problem?
Be sure to set the alpha component to 1.0 when you call glClearColor(0.0, 0.0, 0.0, 1.0).

XNA Alpha Blending part of a texture in Game Studio 4.0

Hi I'm trying to follow an answer about making part of a texture transparent when using Alpha Blending from this question
The only problem is that this only works in XNA 3.1 and I'm working in XNA 4.0 so stuff like RenderState doesn't exist in the same context, and I have no idea where to find the GfxComponent class library.
I still want to do the same thing as in the example question, a circular area radiating from the mouse position that makes the covering texture transparent when the mouse is hovering over it.
3.5
GraphicsDevice.RenderState.AlphaBlendEnable = true;
4.0
GraphicsDevice.BlendState = BlendState.AlphaBlend;
See Shawn Hargreaves post for more info: http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx
EDIT: In the post you can see Shawn using BlendState. You create a new instance of this, set it up however you like, and pass this to the graphics device. Like so:
BlendState bs = new BlendState();
bs.AlphaSourceBlend = Blend.One;
bs.AlphaDestinationBlend = Blend.Zero;
bs.ColorSourceBlend = Blend.Zero;
bs.ColorDestinationBlend = Blend.One;
bs.AlphaBlendFunction = BlendFunction.Add;
graphicsDevice.BlendState = bs;
That clearer?

PDF Annots on iOS with Quartz

Hmm, spending a couple of days trying to get the PDF annotations on my iPad application.
I'm using the following code to get the annotations, and yes! it works :)
But the rect value is completely different then the IOS rect values.
I can't figure it out how to place UIButtons on the spot where the annotation supposed to be.
For example, i have an annotation in the top left corner of the pdf file.
My /Annots/Rect values are, 1208.93, 2266.28, 1232.93, 2290.28 (WHAT?!)
How can i translate the PDF /Annots /Rect values to iOS x an y coordinates?
CGPDFPageRef page = CGPDFDocumentGetPage(doc, i+1);
CGPDFDictionaryRef pageDictionary = CGPDFPageGetDictionary(page);
CGPDFArrayRef outputArray;
if(!CGPDFDictionaryGetArray(pageDictionary, "Annots", &outputArray)) {
return;
.... .... ....}
I think those coordinates are in the "default user coordinate space" of the PDF. You need to apply a transformation that sends them into screen coordinates. You can use CGPDFPageGetDrawingTransform to get such a transformation. Make sure you're using the same transformation for drawing the page and the annotations.
I am not sure if this is the problem but the Quartz 2D Coordinate Systems begins at the bottom left.
See Quartz 2D Programming Guide's Coordinate Systems for more information.
Ps. If you got it working, I would like to see the result code for annotating.
EDIT:
Just found this code (not tested):
// flip context so page is right way up
CGContextTranslateCTM(currentContext, 0, paperSize.size.height);
CGContextScaleCTM(currentContext, 1.0, -1.0);
Source

Resources