Day 94 to 95 – Make my first iPhone app in 16 weeks (UIView)

This is part of “Make my first iPhone app in 16 weeks” series

There are two ways to draw something on screen:

  1. OpenGL (C API)
  2. Quartz (drawing kit), UIKit (display kit), or Core Animation (translation, transformation, rotation animations)

Regardless of which method you use, the drawing must happen within UIView or its subclasses.

The View Drawing Cycle

  1. drawRect: method is called on the view to display the contents. As the name of method implies, iOS passes a rectangle with the visible contents to the view. Override this method for custom views but NEVER call this method yourself.
    1. drawRect is called when the view appears initially
    2. Also it’s called automatically when the following events happen
      1. Moving or removing another view that was partially obscuring your view
      2. Making a previously hidden view visible again by setting its hidden property to NO
      3. Scrolling a view off of the screen and then back onto the screen
      4. Explicitly calling the setNeedsDisplay or setNeedsDisplayInRect: method of your view
  2. The view marks itself as updated and waits for new actions to arrive and trigger another update cycle
  3. If you want to manually change/update the contents of the view, call the setNeedsDisplay or setNeedsDisplayInRect:

Coordinate Systems

  1. User coordinate system – used when a user issues drawing commands
  2. View coordinate system – fixed coordinates relative to the view
  3. Hardware coordinate system – fixed coordinates on the physical device

Points vs Pixels

The purpose for using points system is to render relatively the same size output independent of the device. For example, one pixel line in retina display may correspond to one point which may map to 2 physical pixels (depends on the contentScaleFactor of the view). If you need a custom scale factor, adjust it in drawRect.

Each view has drawing context (CGContextRef) that describes stroke, color, fill and etc. To get the current drawing context, call UIGraphicsGetCurrentContext function.

Animating UIView

There are some built-in animations you can do with UIView without interacting directly with Core Graphics framework. Read documentation here.

Where as UIImage takes into account scale factor and appropriately displays the contents automatically, Quartz images do not account for scale factor. User should check the scale factor and adjust the image size accordingly.

Draw in Offscreen Bitmap

  1. Create a CGRect
  2. Set drawing context with UIGraphicsBeginImageContextWithOptions function
  3. Draw the image in that rect

Day 78 to 79 – Make my first iPhone app in 16 weeks (Perspective Transform)

This is part of “Make my first iPhone app in 16 weeks” series.

Tristimulus value (RGB color) breakdown

  1. Intensity (brightness) – scalar value
  2. Chromaticity (color) – 2-vector (Red and Green. Blue is thrown away by convention as Blue can be deduced by knowing Red and Green) – R / (R + G + B) + G / (R + G + B) + B / (R + G + B) = 1

Homography matrix – used in warping the image

White paper on how to  estimate the ratio of the paper used -here (Someone else’s implementation)

Different transform explained here




Silicon Valley vs Silicon Hills

Silicon valley vs Silicon hills – It’s a hairy question

Silicon hills

Photo courtesy of Silicon Maps, Inc.

So I’ve lived in Austin (aka. Silicon Hills along with San Antonio) for about 10 years before I moved to San Francisco. I have to admit Austin has grown so much for the last decade due to the influx of people moving from California. Thanks to SXSW, the charming little city gained its fame for its tech savviness, entrepreneurship and small business friendly environment. Not only are people coming to Austin but also companies relocate their headquarters to Austin – no State tax is probably the most contributing factor here and the close second being highly educated population thanks to Univ. of Texas at Austin. Also the living expense is half that of SF.

So by now it sounds like I made the biggest mistake by moving to SF. But no. Since I moved to San Francisco, I realized Austin still has so much room to grow. The startup community in Austin still is fledgling and more cliquish than in San Francisco. Almost everyone I met in SF so far is either working at a startup, owns one him/herself or working on one on the side. Everyone’s life is in one way or another intertwined with the startup spirit in this city. That’s not the vibe you would get in Austin, unless you try to actively seek out those special groups. This will change of course in the future, but as of now the support system in SF for young entrepreneurs is just unrivaled best.