Tip

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

Tip

How to Find the Index of a Checked Row in a Table Using jQuery

I’ve been working on a web app for work recently (not my forte), so I’ve been learning a lot of jQuery recently and thought I’d share a little snippet that took me far too long to write:

Basically, what the snippet does, is scan through the table I have on my page and return an array of every row thats had a checkbox checked in. Super simple, but with my limited knowledge incredibly frustrating. Anyway, I hope this helps anyone else that’s had the same issue.

Project Update

TFSliderView

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.
Tip

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.

Tip

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.
Tip

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:

Tip

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!