How to Use the UINavigationController Swipe Back Gesture with a UIPageViewController

I’ve been working on an app at work that’s “Snapchat-eqsue” (uses a UIPageViewController to page between a full-screen camera and a UINavigationController) when I came across this conundrum. Basically, the app is setup as follows:

Please excuse the poor lighting and shoddy sketch. It's early and I didn't feel like opening Sketch.
Please excuse the poor lighting and shoddy sketch. It’s early and I didn’t feel like opening Sketch.

So the Camera is the leftmost view in the PageViewController and the UINavigationController, along with all the views it will add to its stack, is on the right. Things got a bit tricky though when our designer wanted to avoid using physical back buttons on the navigation stack and have the traditional swipe back take you to the previous page. My first instinct was to intercept the PageController gestures, but when it’s set to scrolling, those don’t actually exist–the gesture array comes up empty. That’s when I came up with this fun little hack that’s incredibly easy to do.

The tl;dr is you disable the UIPageViewController’s UIScrollView when the NavigationController displays any view that’s not the root view controller and add a swipe gesture recognizer to each of the subviews. While this sounds like a lot of tedious work, it’s actually really easy if you just subclass UIViewController and use that app-wide (which is actually nice for a variety of reasons like themeing–but that’s for another post).

Project Update


687474703a2f2f692e696d6775722e636f6d2f6f3071535754722e676966Just a quick, shameless, plug for my first Cocoapod: TFSliderView. I needed to make an animated toggle switch that I could use in a number of locations for an in-house project my dev shop is working on, so I decided to make it into a Cocoapod and share it in case anyone else needed something similar.

It’s built off of POP (Facebook’s animation framework) and, all in all, is pretty simple to use. You can install it with Cocoapods using the following line:

pod "TFSliderView", "~> 0.1.0"

And then you just create a view programmatically (as shown below), and call the toggle delegate methods to do whatever it is you need to when the view toggles:

I still have a list of to-dos I want to get done to make the pod more useful, including the below, but I wanted to share what I have so far.

  • Support for up to four buttons.
  • More convenient init methods to accompany the one monster of a designated initializer.
  • Generic starting values for [TFSliderView new].
  • Allowing each toggle state to have a unique color.
  • Complete documentation.

AFNetworking: Downloading Files with Progress

I was looking for this the other day, and while there are a ton of solutions out there, I felt that all of them were just a tad more complicated than they needed to be to achieve the desired result. Basically, I’m working on an app that needs to download videos and show what percentage of the files have been downloaded in a UITableView. Standard stuff, but for some reason it’s not already built in to AFNetworking. After tinkering around with a few different solutions online, I ended up coming up with my own (shown below). I ended up creating a class called MFVideoDownloader and adding the the following class method to the .m:

While the snippet contains more detailed comments, I’ll just go through what I did really quickly.

    1. First I created the session manager to handle the actual download task that comes about later in the method.
    2. Then I converted the given NSString into an NSURL so it can be used later (I’m working with a REST API that gives me back the URLs I need as strings so it made more sense to convert it here rather than have to convert every place I call the method in app).

Inverting a UIColor

More safekeeping than anything else (and because I didn’t see it online anywhere):

Super simple method that’s surprisingly useful if you have something like different themes in an app.


Triangular Imageviews

Certainly not the most climactic way to break my year long posting drought, but I’ve been working on an in house app for my devshop that requires a bunch of triangular UIImageviews and I thought I’d share a quick snippet:

The code itself is pretty simple but just a couple of quick notes on the values used:

  • The 44 value in step 1 is the height of the original view, while 60 is the width (and 30 is half that). I tried using more dynamic values (setting 44 to imageview.frame.size.height etc.) but for some reason when using dynamic values in UITableViewCells I’d get some sizing issues and so I opted to hard code the values in. (I’m assuming because it’s still doing some layout calls.)
  • This code actually isn’t limited to just triangles. By modifying the path in step 1 you can make the ImageView any shape at all, it’s just a matter of playing around with the coordinates until you get something you like.

Removing Articles from an NSString

Not much to say about this one. I put this together while trying to ignore the basic articles in front of a song name in my music app. Takes a given NSString and returns a new one sans the article:

You can call it as follows:

Project Update

Building a Better Music App: Getting Organized

IMG_5910 After a long weekend of lots of ugly refactoring moving from AVPlayer to AVAudioPlayer and then back again (more than once because I couldn’t make up my mind) I decided that it would probably benefit me to get just a little more organized in my pursuit of putting together my music app. On that end, spent a few hours the other night putting my ideas on paper and then fleshing them out in a much more thought out approach. On that end, the first thing I start with as clearly defining all of the functionality I’d like my player to have by the time I graduate from Flatiron:

Overall Desired Functionality

  • Play local music
  • Play music on iTunes Match
  • Play songs from Spotify
  • Play playlists from Pandora
  • Play Soundcloud Streams
  • Scrobble to Last.fm
  • Enable favoriting of songs, playlists, and artists
  • Global search across services
  • Specific search narrowed down by service
  • Location based playlists

How to Stop a UISlider from Stuttering in an AVPlayer

After hours of Googling and trying absurdly complex solutions from old documentation to stop the scrubbing bar on my music player from jumping when I dragged it I finally found the solution and it’s annoyingly simple. Just add a call to not update the slider when it’s being touched inside of your update method like so:

Hopefully this tip will save someone else from having to go through the multiple refactoring attempts I did!