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 :)

The Deep End: What I Learned From My First App Submission

Day 24

I haven’t posted in a while but I have a good excuse! About a week ago I found out about a competition Sensis Australia were holding for developers to create an application that uses their new API.

Now, at this point I’d only been learning iOS development for about a month or so in my free time; I wasn’t ready for a full blown, public application. Not only that, but in order to get it in the App Store in time I would need to create the app – from start to finish – within a week.

That’s bonkers…but, you know, zombies! I can’t say no to zombies!

And so, after 6 days and about 100 hours of working non-stop – pausing only for Mothers Day on Sunday – I created my first application. I learned more in those 6 days than I had in the entire time I’d been learning iOS. I’m glad I did it, and think I’m ready for round 2 :) Keep reading →

Drawing in Obj-C: Lines and Circles

Day 14

In a previous post I showed an example of creating a custom view in which I drew a triangle on screen. I thought I’d spend a bit of time taking a closer look at the code and demonstrate how to draw simple shapes in Objective-C.

Example 1: Lines

The following will draw a triangle in the view with green fill and a red stroke. I’ve added a bunch of comments to each line to make it clear what is happening. Keep reading →

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 →