Protocols & Custom Delegates

Day 41

Understanding delegation in iOS vital when creating an app of any complexity, however I found it difficult to find a good, concise explanation of what it is during the early stages of my learning. In this post I’ll try to explain exactly what it is and provide some steps for creating your own custom delegates.

This is not intended to be an exhaustive tutorial, just an introduction to the concepts of what delegation is. I found that once I understood exactly what delegation was and why I might want to use it, Googling the answers became much easier. Keep reading →

Animating Views

Day 34

Now that I’ve popped my App Store cherry, I’m ready to get serious. I’ve started working on a project that requires the animation of a UIView. For this post I’ve created the following scene where the red box moves to a random point within the white box whenever the user clicks the “Move Red Box” button:

Download the project here to look at how everything works. The magic happens in the TopView.m file:

Whenever moveBoxTo is triggered, the x and y coordinates defined in the point parameter are used to reposition it. The parameters are:

  • animateWithDuration
    As the name suggests, the duration for the animation.
  • delay
    You can delay the start of the animation (in seconds) here.
  • options
    Here you can define the type of animation, such as easing in or out.  See UIView Class Reference for the options available.
  • animations
    A block which defines what properties the target object should animate. In this case, I’m animating the frame property.
  • Completion
    Another block which is triggered once the animation completes.

Here’s an example of how you might call the method:

Download Project File

I’ve skipped over the finer points to keep things simple. Download the project file here to poke around :)

Custom Sub Views

Day 11

Placing and drawing UIView objects using the Object Library works a lot of the time, but there are instances where you’ll need to create your own custom views. A sub view is just a UIView object placed within a parent view. They can be created through the GUI by dragging out an object such as a button or label, or programatically.

There are two common reasons why you’d want to create a custom sub view:

  1. You want create a custom drawing on the screen; or
  2. You want to handle touch events in a way different from the defaults
I’m creating this using a new, single-view application project. Keep reading →

IBOutlet and IBAction

Day 10

Storyboards make it really easy to arrange objects in a view, but you’ll also need a way to control those objects and handle events in your Controller. As a web developer, this usually means either setting up JavaScript triggers or refreshing the page; in iOS development it means using IBOutlets and IBActions.

In this post I’ll outline how to connect view objects to your video controllers using IBOutlet and IBAction.  Keep reading →