Archive for December, 2008
Tilt-shift video
Tilt shift photography is a technique where a photograph’s focus appears blurred and only the center of the subject is in focus (there’s more to it, but that’s the gist of it). You can simulate it in Photoshop but it’s probably easier (albeit more expensive) to use special tilt-shift lenses. The effect is pretty cool, as if you’re photographing a miniature set. Some background on the technique here and here and some beautiful examples here.
The effect is used to stunning effect in this time-lapse music video made entirely with a tilt-shift lens:
Metal Heart from Keith Loutit on Vimeo.
Be interesting to see what would result if you put together the amazing Canon EOS 5D Mark II HD and a decent TS lens…
Easy UIView debugging on the iPhone
The user interface of the iPhone is based on a series of nested UIView objects, arranged in a view-subview/parent-child relationship. When building a complex application with a lot of views, sometimes it’s handy to be able to see exactly what that relationship is.
But if you try to print out the value of a UIView in the debugger (or through an NSLog function) you’ll be sorely disappointed. In this example we have a variable called front that is derived from a UIView. Setting a breakpoint in the XCode debugger, I type in a po (print object) command to show what that variable contains:
(gdb) po _front
<BCCardSideView: 0x106b020>
What you see is that the variable is of type BCCardSideView and its hex address. Not very helpful.
One solution is to take advantage of the Objective-C dynamic runtime and override UIView’s default describe method. This is the method that is called every time you try to display the value of an object. Here we have just such an override that recursively walks the view tree and dumps out the values. The code is contained in a file called UIViewExtras.m. All you have to do to enable it is include the file in your XCode project. There are no explicit methods to call.
Here’s the same output after UIViewExtras.m is included in the project (the indentation is a little messed up because of the column width of this blog. In the debug window, it should look fine):
(gdb) po _front
+ BCCardSideView retain:3 - tag:0 - bgcolor:(r:0 g:0 b:0 a:1.00)
bounds: x:0 y:0 w:130 h:80 - frame: x:5 y:5 w:130 h:80 - center: x:70, y:45
++ BCCardBackgroundView retain:4 - tag:0 - bgcolor:(r:255 g:255 b:0 a:1.00)
bounds: x:0 y:0 w:130 h:80 - frame: x:5 y:5 w:130 h:80 - center: x:70, y:45
++ BCCardTextView retain:4 - tag:0 - bgcolor:(r:0 g:255 b:255 a:1.00)
bounds: x:0 y:0 w:100 h:20 - frame: x:0 y:0 w:100 h:20 - center: x:50, y:10
text (len:4 - color:r:0 g:255 b:0 a:0.00): 'name'
++ BCCardTextView retain:4 - tag:0 - bgcolor:(r:255 g:255 b:0 a:0.00)
bounds: x:0 y:0 w:100 h:20 - frame: x:0 y:20 w:100 h:20 - center: x:50, y:30
text (len:5 - color:r:0 g:255 b:0 a:0.00): 'title'
++ BCCardTextView retain:4 - tag:0 - bgcolor:(r:0 g:0 b:255 a:1.00)
bounds: x:0 y:0 w:100 h:20 - frame: x:0 y:40 w:100 h:20 - center: x:50, y:50
text (len:5 - color:r:0 g:255 b:0 a:0.00): 'email'
++ BCCardTextView retain:4 - tag:0 - bgcolor:(r:255 g:0 b:0 a:1.00)
bounds: x:0 y:0 w:60 h:20 - frame: x:0 y:60 w:60 h:20 - center: x:30, y:70
text (len:7 - color:r:0 g:255 b:0 a:0.00): 'phone.1'
For each view object you see:
- The retain count.
- The tag value (if specified).
- The background color value in RGBA. RGB values are scaled up to 0..255 and alpha is shown as a floating point value between 0 and 1.
- View bounds rectangle (x, y, width, height)
- View frame rectangle (x, y, width, height)
- View center (x, y)
If view is a UILabel or UITextField, you also get:
- - Length of text
- - RGB value for text itself (vs. the background)
- - Actual value of the ‘text’ inside the field.
Subviews are indented by multiple “+” (plus) signs. So the top-level has one ‘+’ all its subviews have two ‘+’ signs, *their* subviews will each have three ‘+’ signs etc.
I personally find this handy in debugging views — especially those created dynamically. I hope you do too.
[ Download: UIViewExtras.zip ] (Update: Link updated.)
Update 2 [06-Oct-09] : Modified method of obtaining class name so it should work with newer SDK releases.