Thoughts on Web Development
More cool animation Wednesday, March 24, 2010 11:13 AM
iPhone applications often use multi-view patterns as their way of navigating through the application's hierarchy. Switching between views is relatively easy to accomplish. But the icing on the cake is the addition of animations to make the transition more interesting for the user.

The basic pattern for switching between two views  is that you check one view's superview and if it's nil, then you know that is the one you want to display. Otherwise, it's the other. The way to add animation to that pattern is as follows:

	[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

if (self.firstViewController.view.superview == nil)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.view cache:YES];
[firstViewController viewWillAppear:YES];
[secondViewController viewWillDisappear:YES];
[secondViewController.view removeFromSuperview];
[self.view insertSubview:firstViewController.view atIndex:0];
[secondViewController viewDidDisappear:YES];
[firstViewController viewDidAppear:YES];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view cache:YES];
[secondViewController viewWillAppear:YES];
[firstViewController viewWillDisappear:YES];
[firstViewController.view removeFromSuperview];
[self.view insertSubview:secondViewController.view atIndex:0];
[blueViewController viewDidDisappear:YES];
[yellowViewController viewDidAppear:YES];
[UIView commitAnimations];

This particular animation uses curl-up and curl-down. The other transition is flip-right and flip-left,

0 Comment(s) Add comment
UITableView Appearance and Behavior and TableViewCells Monday, March 22, 2010 6:07 PM
UITableView Appearance and Behavior
    + Customize appearance and behavior
    + Keep application logic separate from view
    + Often the same object as datasource
    + Customize appearance of table view cell
    + tableView willDisplayCell forRowAtIndexPath, etc.
    + Row selection in TableViews
        - In iPhone applications rows rarely stay selected
        - Selecting a row usually triggers some event
    + Convenient starting point for view controller with a TableView
        - Table view is automatically created
        - Controller is tableviews delegate and datasource
    + Takes care of some default behavior
        - Calls -reloadData the first time it appears
        - Deselects rows when user navigates back
        - Flashes scroll indicator
TableView Cells
    + Designated Initializer
        - initWithStyle (initWithFrame has been deprecated)    
    + Basic properties include an imageView and two text labels
    + Customizing the content view for cases where a simple image + text doesn't suffice
        - Add additional views to the content view

0 Comment(s) Add comment
TableViews Monday, March 22, 2010 5:52 PM
    + Display lists of content
        - Single column, multiple rows
        - Vertical scrolling
        - Large data sets
    +Powerful and ubiquitous in iPhone applications
    + TableView styles
        - UITableViewStylePlain
        - UITableViewStyleGrouped
    + TableView Anatomy
        - Table headers and footers
        - Section headers and footers
        - TableCells
    + How to implement - a naive solution
        - Table views display a list of data so use and array
        - Issues with this approach
            All data is loaded upfront
            All data stays in memory
    + A better approach - the data source protocol
        Another object provides data to the data view
        Not all at once
        Just as it's needed for display
    + Like a delegate but purely data oriented
        Provide number of sections and rows
        Provide cells for table view as needed
    + NSIndexPath
        - Path to a specific node in a tree of nested arrays
    + NSIndexPath and TableViews
        - Cell location described with an index path
        - Category on NSIndexPath with helper methods
    + Single Section Table View
        - Return the number of rows
        - Provide a cell when requested
    + Cell Reuse - queue and dequeue ReusableCellWithIdentifier
    + Triggering Updates - when is the datasource asked for its data?
        - When a row becomes visible
        - When and update is explicitly requested by calling -reloadData
0 Comment(s) Add comment
ScrollViews Monday, March 22, 2010 5:18 PM
Scroll Views - UIScrollView
    + For displaying more content than can fit on the screen
    + Handles gestures for panning and zooming
    + Noteworthy subclasses UITableView and UITextView
    + Pieces which make up a ScrollView
        - Content size
        - ContentSize.width
        - contentSize.height
        - contentInset.top
        - contentInset.bottom
    + contentInset can give you the extra space for other controls
    + Scroll Indicator Insets - allows room for the scroll indicators
    + Tracks where you're at in the content - contentOffset
    + Using a ScrollView
        - Create with the desired frame
        - CGRect frame = CGRectMake(0, 0, 200, 200);
        - scrollView = [[UIScrollView alloc] initWithFrame: frame];
        - Add subviews (frames may extend beyond scrollview bounds)
        - Set the content size
    + Extending ScrollView Behavior
        - Applications often want to know about scroll events
            When the scroll offset is changed
            When dragging begins or ends
            When deceleration begins and ends
    + Typical ways to handle events
        - Create a subclass
        - Override methods to customize behavior
            Application logic and behavior is now part of a view class
            Tedious to write one-off subclass for every scroll view instance
            Code becomes tightly coupled with superclass
        - Extending with Delegation
            Delegate is a separate object
            Clearly defined points of responsibility
                Change behavior
                Change appearance
            Loosely coupled with the object being extended
        - UIScrollViewDelegate
            @protocol UIScrollViewDelegate<NSObject>
            // respond to interesting events
            - (void)scrollViewDidScroll:(UIScrollView *)scrollView;
            // Influence behavior
            -(BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
0 Comment(s) Add comment
Cool iPhone Animation stuff Monday, March 22, 2010 11:24 AM
I was working on a sample to position buttons and ran across UIView.beginAnimations and UIView.commitAnimations which were cool enough. But when you add setAnimationCurve and setAnimationDuration it becomes even cooler!

fromInterfaceOrientation duration:(NSTimeInterval)duration
UIInterfaceOrientation toOrientation = self.interfaceOrientation;

[UIView beginAnimations:@"move buttons" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:2.0f];

if (toOrientation == UIInterfaceOrientationPortrait || toOrientation == UIInterfaceOrientationPortraitUpsideDown) {
// position elements
else {
// position elements

[UIView commitAnimations];

0 Comment(s) Add comment
iMac and Parallels Strangeness Saturday, March 20, 2010 3:31 PM
I've installed a virtual desktop software on the iMac which is supposed to let me use Windows. The virtual machine software is Parallels. I was installing Microsoft Office 2007 on the iMac's Parallels desktop when it asked me to authenticate the copy. For some reason Office's authentication component wouldn't let me go over the internet to run the authentication. So, I had to call the automated authenticator on the phone. All things considered, it wasn't so bad.
0 Comment(s) Add comment
iPhone Tab Bar Controllers Wednesday, March 17, 2010 1:37 PM
    Tab Bar Controllers
        + Array of view controllers
        + How it fits together
            - Selected view controller's view
            - All view controllers' titles
        + Tab bar appearance
            - View controllers can define their appearance in the tab bar
            - UITabBarItem - includes title and/or image (system item)
        + More view controllers
            - What happens when a tab bar controller has too many items?
            - Shows the … More button

0 Comment(s) Add comment
iPhone Navigation Wednesday, March 17, 2010 1:36 PM
Navigation Controllers
        + Stack of view controllers
        + Navigation bar is the topmost bar
    How it fits together
        + Top view controller's view
        + Top view controller's title
        + Previous view controller's title
        + Top view controller's toolbar items (iPhone OS 3.0)
    Modifying the Navigation Stack
        + Push to add a view controller
        + Pop to remove a view controller
        + Set to change the entire stack of view controllers
    Pushing your first view controller
        + during the applicationDidFinishLaunching delegate
        + or in Response to some user action in (void)someAction:(id)sender {…}
        + Almost never call pop directly because it's automatically invoked by the back button
    Connecting View Controllers
        + In the real world multiple view controllers may need to share data
            - Watch for added, removed, or edited data
            - Other interesting events
        + How not to share data
            - Global variables or singletons using your application delegate
            - Direct dependencies make your code less reusable
            - And more difficult to debug and test
        + Best Practices for Data Flow
            - Figure out what exactly needs to be communicated
            - Define input parameters for your view controller
            - For communicating back up the hierarchy, use loose coupling
                by defining a generic interface for observers
    Customizing Navigation
        + Buttons or custom controls
        + Interact with the entire screen
        + UINavigationItem
            - Describes the appearance of the navigation bar
            - Title string, left/right bar buttons
            - Every view controller has a navigation item for customizing
            - Left & right buttons
            - System Bar Button Item
            - Edit/Done Button
            - Custom title view
            - Back button
0 Comment(s) Add comment
CS193P Notes - Model-View-Controller Architecture - View Controllers Monday, March 15, 2010 11:28 AM
View Controllers (Part 2)
View Controllers
    > Problem: Managing a Screenful
        + Controller manages views, data, and application logic
        + Apps are made up of many of these
        + Is a great starting point
    > Problem: Building Typical Apps
        + Navigation-based
        + Tab bar-based
        + Combination of the two
        + Typically plug individual screens together to build an app
    > UIViewController
        + Basic building block
        + Manages a screenful of content
        + Subclass to add your own application logic
    > Your View Controller Subclass
    > The "View" in "ViewController"
        + UIViewController superclass has a view property
        + It loads lazily
            - On demand when requested
            - Can be purged on demand as well
        + Sizing and positioning the view
            - Depends on where it's being used
            - Don't make assumptions, be flexible
    > When do you call -loadView?
        + Don't do it - step away from the loadView.
        + Cocoa tends to embrace a lazy philosophy
            - Call -release instead of dealloc
            - Call -setNeedsDisplay instead of -drawRect
        + Allows for work to be deferred or coalesced
    > Creating Your View in Code
        + Override -loadView
        + Create your views
        + Set the view property
        + Create view controller with -init
    > Creating your view with Interface Builder
        + Layout a view in Interface builder
        + File's owner is view controller class
        + Hook up view outlet
        + Create view controller with -initWithNibName:bundle:
    > View Controller Lifecycle
        + -(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle
        + -(void)viewDidLoad{}
        + -(void)viewWillAppear:(BOOL)animated{}
    > Loading and Saving Data
        + NSUserDefaults
        + Property lists
        + CoreData
        + SQLite
        + Web services
    > More view controller hooks
        + Low memory warnings
        + Interface Rotation
0 Comment(s) Add comment
CS193P Notes - Model-View-Controller Architecture - View Controllers Monday, March 15, 2010 11:26 AM
Model-View-Controller Architecture - View Controllers (part 1)
Designing iPhone Applications
    > 320x480 resolution prohibits busy screens and non-essential info
    > Maximize the data
    > Show one thing at a time
Patterns for organizing content
    > Navigation bar
        + hierarchy of content
        + Drill down into greater detail
    > Tab bar - different views of the same information
        + Self-contained modes - think about the clock app
Apps show screenfuls of data
    > Slices of your application
    > Views, data, and logic
    > Clear responsibility
    > Write less code
    > Funny, they don't mention testing; either unit or TDD
How do the Model/View/Controllers communicate with each other?
    > Model - typically the most reusable
        + Not aware of views or controller
        + Key-value observing
        + Notifications - custom messages
    > View - tends to be reusable
        + Not aware of controllers but may be aware of relevant model objects
        + Communicates with controller using
            - Target action
            - Delegation
    > Controller - knows about model and views objects
        + Brains of the operation
        + Typically app-specific - least reusable of the three layers (?).
0 Comment(s) Add comment
Basic iPhone Dev notes - Cocoa and Objective C Sunday, March 14, 2010 4:33 PM
Cocoa Touch is the basic framework for iPhone applications. This framework was designed around a Model-View-Controller (MVC) architecture. The View is the user-interface portion of the application. The Model is where the application data is handled. The Controller is the portion of the application which binds the View and the Model together. The View and the Controller can talk back and forth. The Model and the Controller can talk back and forth. But the Model and the View shouldn't speak to each other. This separation of concerns is one of the attractive aspects of this architecture.

(As a side note, the MVC architecture is also used as an alternative architecture to WebForms in the latest ASP.NET releases.)

Outlets are instance variable that are declared using the keyword IBOutlet. You can think of an Outlet as a pointer that points to an object within the NIB. It is through these outlets that your controller class talks to your user interface objects in the NIB file (or View).

Actions are methods in the controller class. They can be thought of as ways which objects in your NIB file (view) can talk with your controller class (Controller).

Cocoa also makes extensive use of Delegates (a familiar concept from .NET), which are classes that take responsibility for doing certain things on behalf of another class/object/type.

One more intro tidbit is that Objective C uses angle brackets to indicate that a class conforms to a certain protocol. A protocol is a group of methods.

Interface Builder is more than UI layout control. Also, it will create instances of any other classes you specify.
0 Comment(s) Add comment
CS193 Lecture 5 (part 2) Wednesday, March 10, 2010 1:42 PM
Graphics Contexts
    All drawing is done into an opaque graphics context
    Draws to screen, bitmap buffer, printer, PDF, etc.
    Do not cache a CGContext!
CG Wrappers
    Some CG functionality wrapped by UIKit
    UIColor - easily sets the fill and/or stroke
    UIFont - Get font by name
Drawing more complex shapes
    Get current graphics context
    define a paths
    Set a color
    Stroke or fill path
    Repeat, if necessary
More Drawing Information
    UIView Class Reference
    CGContext Reference
    Quartz 2D Programming Guide
Images and Text
    UIImage - represents an image
Text, Images and UIKit views
    Use UILabel
        -shadow (offset and color)
    UIView that draws UIImages
    UIView - contentMode property to align and scale image with regards to bounds
    UIView with Target-Action event handling
    Properties include:
Animating Views
    UIView supports frame, bounds, center, alpha, transform animations
    Additional animation options include
        -delay before starting
        -start at a specific time
        -curve (how fast the ease in/out occurs)
        -repeat count
    Use delegates to determine when the animation starts and stops
Core Animation
    Hardware accelerated rendering engine
    UIViews are backed by "layers"
    What's drawn is then composited by a separate process
    Property animations are done automatically by manipulating layers
View Transforms
    Every view has a transform property
    CGAffineTransform structure is used to represent transform
    Use CG functions to create/modify transforms
For more animation information
    iPhone OS Programming guide
        -Modifying Views at Runtime
    Core Animation Programming Guide
Hints for assignment 3
    NSUserDefaults to read and write preferences and state
        -Singleton object
        -Includes methods for storing and fetching common types
0 Comment(s) Add comment
CS193 Lecture 5 (part 1) Wednesday, March 10, 2010 1:41 PM
Views, Drawing, and Animation

View Fundamentals
    Rectangular area on screen
    Responsible for drawing
    Responsible for handling events
    Subclass of UIResponder (event handling class)
    Views are arranged hierarchically
        -every view has one superview
        -every view has zero or more subviews
View Hierarchy - UIWindow
    View live inside of a window
    UIWindow is actually just a view
    There is one UIWindow for an iPhonef application
        -contains the entire view hierarchy
        -setup by default in Xcode template project
View Hierarchy - Manipulation
    Add/remove views in IB or using UIView methods
        -(void)addSubview:(UIView *)view;
        -(void)removeFromSuperview - a subView removes itself
    manipulate the view hierarchy manually
View Hierarchy - Ownership
    Superviews retain their subviews
    Views can be temporarily hidden
        -theView.hidden = YES;
View-related Structures (CG == Core Graphics)
    -CGPoint - location in space: {x, y}
    -CGSize - dimensions: {width, height}
    -CGRect - location and dimension: {origin, size}
View-related Structures
    Convenience macros - CGPointMake, CGSizeMake, CGRectMake
UIView Coordinate system
    Origin is in the top left - y goes down
Location and Size
    Frame is in the superview's coordinate system
    Bounds is in the local coordinate system
    Frame is computed
    Center point is stored and from that along with the bounds to get the frame
    Rotation, translation, and scale
Frame and bounds - which to use?
    If you are using a view, typically use the frame
    If you are implementing a view, typically use bounds
Creating Views
    Commonly use Interface Builder
    Manually creating views
        -Initialized using -initWithFrame
            CGRect frame - CGRectMake(0, 0, 200, 150);
            UIView *myView = [[UIView alloc] initWithFrame: frame];
            [window addSubview:label];
            [label setText:@"Number of Sides:"];
            [label release]; // label is now retained by the window
Drawing - (void) drawRect:(CGRect)rect
    Override - drawRect: to draw a custom view
        rect argument is area to draw
Be Lazy
    drawRect: is invoked automatically
    being lazy is good for performance
    When a view needs to be redrawn, use: -(void) setNeedsDisplay;
        -(void) setNumberOfSides: (int)sides {
            numberOfSides = sides;
            [polygonView setNeedsDisplay];

0 Comment(s) Add comment
CS193 Lecture 4 Tuesday, March 09, 2010 3:19 PM
Anatomy of an App, MVC, Nib files, controls & Target-Action

Memory Management
        Alloc/Init - alloc assigns memory;
        -init sets pup the object
        Override -init, not -alloc
        Increment and decrement retainCount
        When retainCount is 0, object is deallocated
        Don't call dealloc
        Object is released when run loop completes

Setters and Getters
    Setter and Getters have a standard format:
    Properties allow access to setters and getters through dot syntax:
        @property age;
        int theAge = person.age;
        person.Age = 21;
Anatomy of an Application
    Compiled code
    Nib files
        - UI elements
        - Details about the object relationships
    Info.plist file (application configuration)

UIKit Framework
    Provides standard interface elements
        - Don't fight the framework
        - Understand the designs

UIKit Framework
    Starts your application
    Every application has a single instance of UIApplication
        -Singleton design pattern
        @interface UIApplication
        - Orchestrates the lifecycle of an application
        - Dispatches events
        - Manages status bar
        - Rarely subclassed
            - use delegation instead

    Control passed to delegate objects to perform application specific behavior
    Avoids need to subclass complex objects
    Many UIKit classes use delegates
        - UITableView
        - UITextField

    XCode project templates have one set up by default
    Object you provide that participates in application lifecycle
    Can implement various methods which UIApplication will call

Info.plist file
    Property List (XML) describing your application
        - Icon appearance
        - Status bar style
        - Orientation, uses WiFi, system requirements
    Can edit most properties in XCode

Model View Controller
    Controller is the intermediary between the Model and View
    View - UI
    Model - where the data is stored
    Outlets and actions are how the Controller, Model, and View communicate with each other

Nib Files - design time
    Helps you design the View
    add controller objects

    Designed to help us understand the MVC application architecture
0 Comment(s) Add comment
Mac OS Getters and Setters and what you're used to Tuesday, March 09, 2010 2:02 PM
I ran into a bit of a problem the other day with using setters and getters. I figured I would use the Object C syntax to set a property. Something like this:

[someThing someProperty:10];

The compiler kept giving me some vague error message and I kept on looking at it. Eventually, I ran across a blog entry which clued me in. If I wanted to something like this, I had to use:

[someThing setsomeProperty:10];

The blog entry was interesting because it was actually talking about using dot notation for setting properties in Objective C. It suggested that instead of using what it called the obvious:

someThing.setsomeProperty = 10;

That you should use the less obvious:

someThing.someProperty = 10;

Coming from .NET programming, the second way to use the dot notation is what I would have thought was pretty obvious. The inclusion of "set" in the property name was not very obvious to me. I guess it's all in where you're coming from.
0 Comment(s) Add comment
Things I like and dislike about Mac OSX Monday, March 08, 2010 12:02 PM
I like the airmouse. I especially like how Apple has implemented the browser Back and Forward commands as a swipe of two fingers on the mouse itself. Pretty sweet.

The single application menu drives me a little batty. I always forget to Command Q the application. So when I Command Tab through applications, I'm always surprised when I see something opened that I thought I closed. I think you should be offered an option on the active window that when you close it by clicking on the close button, that it should also close the application. (hmmm... maybe there is one, like Command click?) With the 27" screen, moving the mouse all the way to the upper right hand corner anytime you want to close an application is a pain. (hmmmm... maybe people don't close their applications on the Mac?)

I'm also having problems with word right and word left keyboard shortcuts. On Windows, their implemented as Ctrl-right arrow and Ctrl-left arrow. On the Mac, they're implemented as Option right arrow and Option-left arrow. Also, it seems that the cursor doesn't actually go to the beginning of the word but to the end of the current word and then to the beginning of the next. But this is nit picky.
0 Comment(s) Add comment
My First IPhone application Thursday, March 04, 2010 8:27 PM
I downloaded the IPhone SDK and associated tools and built my first IPhone application. It doesn't do anything much besides display some text and show a picture. So far, it reminds me a bit of Visual Basic.
0 Comment(s) Add comment
IPhone Development Thursday, March 04, 2010 7:19 PM
IPhone development
  • Tools - XCode and Interface Builder
  • Foundation and UIKit
  • Objective C (runtime?)
Mac OS X consists of
  • Foundation
  • Media
  • Core Services
  • Core OS
The IPhone OS is comprised of the same elements, except Cocoa Touch.
0 Comment(s) Add comment
New IMac Thursday, March 04, 2010 5:46 PM
I got the new iMac up and running. It's a pretty sweet machine. Right now, I'm downloading Apple's dev environment, XCode.
0 Comment(s) Add comment
© LimberTech 2015