Get Updates By E-mail 

coregraphics

How To Draw Objects With Holes Using CoreGraphics

  •  
  •  
  •  
  •  
  •  

Sometimes you will want to draw a more complex shape in an app that doesn’t use OpenGL, and you don’t want to load in the graphics from a file, and this can be done using CoreGraphics.

A situation that can arise is the drawing of one shape within another shape. The easiest way to do this is simply to draw the shape on top of the other shape, but this typically will not give the most efficient performance.

Also, there could be a situation when you want the user to see the background through the shape that you are drawing, and if that background is changing simply drawing shapes over top of each other isn’t going to cut it.

For those situations Matt Gallagher from Cocoa With Love has created a tutorial explaining 5 different techniques for drawing a shape with a hole in core graphics.

For more information on CoreGraphics check out our Resources for Learning Core Graphics and review of  the Core Animation Simplified book.

Please Click Here To Share This Article With Others By Re-Tweeting It.

[Source: Cocoa With Love]


  •  
  •  
  •  
  •  
  •  

Programming Spinning, Scaling Images & Buttons: Code Snippet

  •  
  •  
  •  
  •  
  •  

A few days ago I posted a code snippet of a couple of methods that allowed you to fade a view in and out.  What I didn’t expect was a number of positive messages on youtube, but it made me realize that transforms and animations of UIViews are something that many probably haven’t played around with much.  So I decided to post another method showing how scaling can be used and the interesting effects that can be generated.

Check out the video:

If you’ve studied graphics math you probably know that when scaling reflection occurs if the provided scaling factor is a negative number, and because the scaling used here is done with a 2D matrix that is how the spin effect is produced which is also accompanied by shrinking (or growing).

The method I created to do this is pretty simplistic just like the one in the previous article on fading:
Scaling and Reflecting UI Views using CGAffineTransform


The key here is the CGAffineTransformMakeScale function which performs the matrix math for us with the x and y scaling factors provided.

The project I used to create the video is here:
>>> Scaling UIViews <<<
Something you’ll notice is that zero values are not used (0.01 is used in my project is the lowest scale) this is because providing zero as the scaling factor ends up zeroing everything out and causing the view being scaled to immediately be wiped from the screen.


Check it out, and hopefully you can use it to make your apps, especially your interfaces more interesting.
 


  •  
  •  
  •  
  •  
  •