cs193p – Lecture #13 Application Lifecycle and Core Motion

Please note, this blog entry is from a previous course. You might want to check out the current one.

NSNotification

Notifications provide a way to react to asynchronous events. e.g.:

NSNotificationCenter.defaultCenter()

func addObserverForName(String, // name of the "radio station"
    object: AnyObject?, // broadcaster (or nil for "anyone")
    queue: NSOperationQueue?) // queue to execute the closure on 
    { (notification: NSNotification) -> Void in
        let info: [NSObject:AnyObject]? = notification.userInfo // notification-specific information
}

Continue reading “cs193p – Lecture #13 Application Lifecycle and Core Motion”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #12 Dynamic Animation

Please note, this blog entry is from a previous course. You might want to check out the current one.

The twelfth lecture addresses a different approach to animation, creating sets of behaviors defining how items should interact with each other and the environment.

First we create an animator inside a reference view:

var animator = UIDynamicAnimator(referenceView: UIView)

Continue reading “cs193p – Lecture #12 Dynamic Animation”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #11 Unwind Segues, Alerts, Timers, View Animation

Please note, this blog entry is from a previous course. You might want to check out the current one.

The eleventh lecture is theory only, starting with detailed discussion about the final project (which might only be interesting for Stanford students).

Unwind Segue

Unwind Segues provide a way to segue back to MVCs which directly or indirectly presented the current segue.
Continue reading “cs193p – Lecture #11 Unwind Segues, Alerts, Timers, View Animation”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #10 Table View

Please note, this blog entry is from a previous course. You might want to check out the current one.

Though the lecture is called table view it starts with a “bonus topic”:

UITextField

The keyboard appears when a text field becomes first responder (becomeFirstResponder) and desperadoes when it resigns to be first responder (resignFirstResponder). To know when the return key has been pressed (functextFieldShouldReturn) or when editing has ended (textFieldDidEndEditing) is controlled via delegates or target/action notifications.
Continue reading “cs193p – Lecture #10 Table View”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #9 Scroll View and Multithreading

Please note, this blog entry is from a previous course. You might want to check out the current one.

The lecture starts with additional information on how to control the appearance of a view in different size classes and how to inspect constraints in various size classes.

Scroll Views

Adding sub views to a scroll view works similar like adding views to any other view. The only important difference is to define the content size of the scroll view:

scrollView.contentSize = CGSize(width: 3000, height: 2000)
logo.frame = CGRect(x: 2700, y: 50, width: 120, height: 180)
scrollView.addSubview(logo)
aerial.frame = CGRect(x: 150, y: 200, width: 2500, height: 1600)
scrollView.addSubview(aerial)

Continue reading “cs193p – Lecture #9 Scroll View and Multithreading”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #8 View Controller Lifecycle, Autolayout

Please note, this blog entry is from a previous course. You might want to check out the current one.

View Controller Lifecycle

  • viewDidLoad is called after instantiation and outlet setting (geometry is not set yet!) – use for setup
  • viewWillAppear is called before the view appears on screen (geometry is available) – use for layout setup and updates which happened while the view was off screen
  • viewDidAppear
  • viewWillDisappear – use for cleaning up and saving states
  • viewDidDisappear

Continue reading “cs193p – Lecture #8 View Controller Lifecycle, Autolayout”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Lecture #7 Multiple MVCs

Please note, this blog entry is from a previous course. You might want to check out the current one.

The seventh lecture addresses the interaction of multiple model-view controllers – especially navigation controllers.

Segues

The links between two view controllers are called segues. They always create a new instance of the called MVC and need to initialize that MVC e.g. using prepareForSegue.

Segues can also be prevented from happening using shouldPerformSegueWithIdentifier.

Popover

Where tab-bar, split-view and navigation controllers are view controllers, popovers are not. Though preparing popover segues works similar, their destruction needs special care, making the calling view controller the delegate.

The lecture and its slides are available via iTunes named “7. Multiple MVCs”. The code for the psychologist demo is available on GitHub and at Stanford.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail