Author: admin

  • Tutorial: Implementing UIInterpolating MotionEffect

    This is quite a neat effect that you can add to any of your views on your app. Essentially as you move your phone, the accelerometers inside predict the orientation changes of the phone and provide this movement to your view. It is a great trick to help bring attention to prominent views or images in your app. By creating a small extension on the UIView class you will be able to add this effect to any view with one line of code.

    Tutorial

    First of all, you want to set up a single view application template. Then create a fixed size UIView to contain your main UIImageView. It is important that the clip to bounds attribute for the UIView is set to true and the UIImageView is constrained to be larger than the UIView.

    Screen Shot 2018-01-28 at 8.17.12 AM

    Here is the extension that you will need to add to your project that you can use on any UIView or subclass of UIView.

    https://gist.github.com/rtking1993/e0692e99f0dde15b3cbb32eee0ef8ca0

    Then we want to connect our UIImageView to an outlet and implement the motion effect in the viewDidLoad method.

    https://gist.github.com/rtking1993/2e31ae78464b0aa2a8b54f26c9cda06c

    Adjusting the intensity will change the severity of the effect, reducing the intensity will make the effect less pronounced while increasing the intensity will raise the sensitivity. Be careful of setting the intensity too high, as it could leave your users feeling a bit nauseous!

    Here is the full source code for the project:

    https://github.com/rtking1993/UIImagePickerViewController

  • Tutorial: Creating custom UIViews

    Creating custom UIViews can be very useful for many reasons; code reusability, view controller code reduction and improve maintainability. It enables you to build one component and use it in multiple places around your application. This will reduce the total number of lines in your project and enable you to make changes to your component in one place as opposed to many. View controllers can often get bloated with code that can be delegated to the views of the controller.

    Tutorial

    Here is an example of a custom UIView XIB. The view contains one button, which when pressed fires a delegate method that should be handled inside your ViewController.

    Screen Shot 2018-01-31 at 15.54.42

    Here is the code for the TestView and the TestViewDelegate. The TestView has a container view, UIButton, and delegate. Ensure that the container view and UIButton are connected up to the XIB properly. You will need to create an IBAction to handle the button press on the TestView, inside this action method you will fire the delegate method which will be sent to the parent UIViewController that conforms to TestViewDelegate.

    https://gist.github.com/rtking1993/6cce0b7629c76bb113484c9754553d30

    Now that our TestView is set up correctly, we simply have to place it onto our UIViewController, create an IBOutlet to it and set its delegate properly. Once we have done those three steps, the TestView will fire back a delegate call every time its “Action” button is pressed. Enabling our TestViewController to handle that button press further, in this case by printing a simple statement.

    https://gist.github.com/rtking1993/acba1a35650568e95ef572084c86c260

     

    Here is the full source code for the project:

    https://github.com/rtking1993/CustomUIView

  • Code Snippet: UIAlertController Error Extension

    It is an essential part of software development to handle errors correctly and iOS development is no different. It is important to reduce the impact of the error to your user and inform your user clearly if an action is required.

    Here is the extension that you will need to add to your project and the implementation of how you would present the UIAlertController within a UIViewController class.

    https://gist.github.com/rtking1993/26a4d36a69563f38f5e726949b6edd67