inaka

Latest blog entries

/
The Art of Writing a Blogpost

The Art of Writing a Blogpost

Mar 09 2017 : Matias Vera

/
SpellingCI: No more spelling mistakes in your markdown flies!

Feb 14 2017 : Felipe Ripoll

/
Fast reverse geocoding with offline-geocoder

Do you need a blazing fast reverse geocoder? Enter offline-geocoder!

Jan 18 2017 : Roberto Romero

/
Using Jayme to connect to the new MongooseIM REST services

MongooseIM has RESTful services!! Here I show how you can use them in an iOS application.

Dec 13 2016 : Sergio Abraham

/
20 Questions, or Maybe a Few More

20 Questions, or Maybe a Few More

Nov 16 2016 : Stephanie Goldner

/
The Power of Meeting People

Because conferences and meetups are not just about the technical stuff.

Nov 01 2016 : Pablo Villar

/
Finding the right partner for your app build

Sharing some light on how it is to partner with us.

Oct 27 2016 : Inaka

/
Just Play my Sound

How to easily play a sound in Android

Oct 25 2016 : Giaquinta Emiliano

/
Opening our Guidelines to the World

We're publishing our work guidelines for the world to see.

Oct 13 2016 : Brujo Benavides

/
Using NIFs: the easy way

Using niffy to simplify working with NIFs on Erlang

Oct 05 2016 : Hernan Rivas Acosta

/
Function Naming In Swift 3

How to write clear function signatures, yet expressive, while following Swift 3 API design guidelines.

Sep 16 2016 : Pablo Villar

/
Jenkins automated tests for Rails

How to automatically trigger rails tests with a Jenkins job

Sep 14 2016 : Demian Sciessere

/
Erlang REST Server Stack

A description of our usual stack for building REST servers in Erlang

Sep 06 2016 : Brujo Benavides

/
Replacing JSON when talking to Erlang

Using Erlang's External Term Format

Aug 17 2016 : Hernan Rivas Acosta

/
Gadget + Lewis = Android Lint CI

Integrating our Android linter with Github's pull requests

Aug 04 2016 : Fernando Ramirez and Euen Lopez

/
Passwordless login with phoenix

Introducing how to implement passwordless login with phoenix framework

Jul 27 2016 : Thiago Borges

/
Beam Olympics

Our newest game to test your Beam Skills

Jul 14 2016 : Brujo Benavides

/
Otec

Three Open Source Projects, one App

Jun 28 2016 : Andrés Gerace

/
CredoCI

Running credo checks for elixir code on your github pull requests

Jun 16 2016 : Alejandro Mataloni

/
Thoughts on rebar3

Thoughts on rebar3

Jun 08 2016 : Hernán Rivas Acosta

/
See all Inaka's blog posts >>

/
PictureViewMaster

The Gera wrote this on May 18, 2016 under ios, ui .

A few months ago I was working, along with some other awesome people, on a sports social media app which had a lot of little cool stuff in it. One of those things was a clickable image view that, when touched, enlarged its image and let the user zoom it and move it. Nothing really awesome, but I'm a simple man, so I spent 2 or 3 minutes playing with that, like a child with a new toy. So, when my time to do open source came and, since I have never had good ideas to do abstract, non-UI cool things, I decided to try and build something that can recreate this behaviour and improve it, so here it is :

PICTURE VIEW MASTER

Basically, it does what I described above, but it also lets you rotate the image. ... ... WOW, right? I'll give you a moment or two to recover from what I've just said, it hit me the same way as you the first time I used it.

Enough talk, lets go to the real point: How do I use it? Read this in case, of course, you want to use it. Otherwise, just close this page and live a normal PictureViewMasterLess empty life.

It is easy. It is divided in an optional part and a mandatory part.

The optional part is not a big deal, just a subclass of UIImageView that adds a Tap Gesture Recognizer to let its delegate know that the user tapped on the image. You can add it by code using the regular UIImage initializers and then setting the delegate, or you can use the custom initializers such as:

PictureMasterImageView(image: image, andDelegate: self)

This will save you one line of code by setting its delegate on the initializer. Remember, each line of code saved is a tree saved. The other way to add it is via interface builder; add a reference and set its delegate by code:

@IBOutlet weak var sampleImage1: PictureMasterImageView!
sampleImage1.delegate = self

Whatever form you choose, you'll have to conform to the PictureMasterImageViewDelegate, and here comes the mandatory part.

func pictureMasterImageViewDidReceiveTap (
pictureMasterImageView: PictureMasterImageView) {
let masterViewController: PictureMasterViewController = 
PictureMasterViewController(
nibName: "PictureMasterViewController",
bundle: nil)

masterViewController.showImage(
pictureMasterImageView.image!, 
inViewController:self)
}

Let me explain this. The pictureMasterImageViewDidReceiveTap method is the one requiered by the delegate. This is mandatory only if you have to conform the PictureMasterImageViewDelegate protocol.

let masterVC: PictureMasterViewController = 
PictureMasterViewController(
nibName: "PictureMasterViewController", 
bundle: nil)

With this I'm just initializing the PictureMasterViewController. The important line of code is this one:

masterVC.showImage(
pictureMasterImageView.image!, 
inViewController:self)

This will set the image you want to manipulate, add the gesture recognizers to that image and present the PictureMasterViewController on the view controller you specify. By default, this comes with all the gesture recognizers enabled (Reset frame, dismiss image, rotate, zoom and drag). However, you can specify which ones you want to be enabled.

let gesturesAllowed = [.BackgroundTap, 
.DoubleTap, .Rotate, 
.Zoom, .Drag]
masterViewController.showImage(
pictureMasterImageView.image!, 
inViewController:self, 
withGestures: gesturesAllowed)

And that's it. There's nothing more to say other than the PictureViewMaster will handle the dismiss itself when the user touches outside the image frame.

Feel free to check the code, change it, erase it and do it from the scratch or show its awesomness to your friends and tell them you did it (Do it for me, I don't have any friends🙁️). Also you can open issues Here or just PR and i'll reject it, because this code is freaking perfect and it laks of failures (No, really, i'll check it and tell you you did an awesome job!😁).