How to scroll an obscured textfield above the keyboard in combination with UIKeyboard notifications

Hello and welcome back!
For a long time I wanted to write about a specific topic that surely every programmer encounters in his/her programming life. A topic not that difficult, but an important one. That is, how to scroll a textfield to a visible area of the view when it's obscured by the keyboard and how to put it back into its original position, after the keyboard vanishes.

Of course, to accomplish something like that, it's necessary to know when the keyboard is about to appear and when it's about to disappear. Therefore, in this post I'm going to work with two subjects evenly important, combined in the package of one.

Let's discuss about it for a while, beginning from the later one. Every time that the keyboard is going to be shown or to be closed, the system (iOS) sends various notifications to the app regarding each state of the keyboard. For example, such notifications are:

  • UIKeyboardDidShowNotification
  • UIKeyboardDidHideNotification
  • UIKeyboardWillShowNotification
  • UIKeyboardWillHideNotification

How to play audio files using the AVFoundation framework

The topic of this tutorial is about the AVFoundation framework, which is a powerful set of tools that let programmers to work with both audio and video related tasks. In here, I’ll make a small introduction on how to play audio files using the framework, which is the most common task for the majority of the developers.
I should mention that the AVFoundation framework is not the only one letting us playing audio files. There are also:
  • Media Player framework
  • Audio Toolbox framework
  • OpenAL framework
and more.

What we’ll do here: Our goal is to create a simple iOS app with a single view, which is going to have three buttons:
  • Play
  • Pause
  • Stop
No need to explain what these buttons are going to do with our audio file. Additionally, we’ll have a label which is going to inform us about the status of the playback.