Mostrando postagens com marcador objective-c. Mostrar todas as postagens
Mostrando postagens com marcador objective-c. Mostrar todas as postagens

sábado, 2 de agosto de 2014

[Quicktips] iOS - Follow Keyboard Animation Behaviour

On getting back to iOS programming I restarted to check into interesting subjects, like the right way of creating view controllers, behaviours and more.

One thing I had to create these last days was some code for a text field to follow the keyboard open/close animation. Then it come to me that we were going to use that behaviour was needed in more places and that it didn't belong to the view controller neither to the view using it.

So in order to achieve that I decided to create a behaviour class which features are:
  • To receive a target view
  • Register under keyboard events
  • Animate the target view to follow the keyboard open/close animation
  • Keep target view before (on top) of keyboard, meaning that target will be hidden when keyboard is closed
This set of features don't break the single responsibility principle since it is responsible only for controlling the animation behaviour of a view following the iOS keyboard.

To achieve our desire the class must subscribe to keyboard notifications and follow keyboard info dictionary in order to animate the same way the keyboard does.



In 1. we retrieve the type of animation, the duration and the final position of the keyboard. The problem with the animation type is that Apple uses a internal value which only works directly with the old animation style.
To use it with animationWithDuration methods we would have to shift the value, this isn't easy to understand and read later so is preferable to keep the old style in this case.

In 2. we use the animation calls on UIView to prepare animation with keyboard info.

In 3. we animate using the keyboard final position, in my case I'm positioning the view right above keyboard, and when dismissed the view will be hidden outside of the screen in the bottom. Also we have to commitAnimations so evertyhing will work properly.

That is all we need to create a behaviour that works with any view.

The class and the demo are available on github.



sexta-feira, 15 de fevereiro de 2013

[iOS] Using UIRefreshControl

In iOS 6 Apple presented us the UIRefreshControl to use with "Pull to Refresh" actions. This control is really easy to use and can be currently used with UITableView, UIScrollView and UICollectionView.

On your -(void)viewDidLoad method or the place where your controller will load for the first time, create and add the refresh control as a subview of the views mentioned above.





The next step is to create the refreshView method, just add it anywhere on your view controller.




That is it, nice and smooth.


domingo, 8 de maio de 2011

Quick Tips - IOS Dev - Documentation Shortcut

This tip was given me by @marcolindoso, one of my co-workers and friend at Parsec Digital.

Most of the times Apple documentation is very useful but we have to copy the code and go to google or the Apple site, so instead of doing this we can use xcode sdk docs. Ok nice idea but the shortcut its too dificult to remember or even to guess if you don't look for it in preferences.

So let's change this:
With XCode opened enter in Preferences (Type: command + ,)
Open key bindings and type "Documentation" in the search field, now you gonna see a list and in that list is the key binding "Search Documentation for Selected Text", select it and type enter
When the key binding open for editing input command + D

Done, now you have easy to remember shortcut for documentation access, to use it put your cursor over any piece of apple documented code and use the shortcut.

Happy coding....