If your iPhone freezes up on you, there are several troubleshooting steps you can take in order to get it working again.
Close Out of the Application
If your iPhone freezes within an application, it may be that the application is causing the issue. To quit the current application, double-tap on the Home button. The app switcher displays with screenshots of every open app. Swipe the window that displays your current application up and off the top of the screen to quit the application.
Restart the iPhone
Sometimes, a simple restart is all it takes to fix a frozen iPhone. Press and hold the Power button for about five seconds. A slide to power off slider appears at the top of this screen. Slide to power off the iPhone and then press and hold the Power button to turn the phone back on.
Perform a Hard Reset
If quitting the current application and restarting does not fix your iPhone, try performing a hard reset. Press and hold the Home button and Power button down simultaneously for about 15 seconds. The iPhone will turn off. Turn the iPhone back and see if the phone is unfrozen.
Performing a hard reset will not affect any of your documents and data, nor will it change any settings on the iPhone.
Restore the iPhone
If the hard reset does not work, try restoring the iPhone using either iTunes on a computer or directly from the device's Settings application.
Restoring through iTunes
Step 1: Plug the iPhone into the Computer
Using the iPhone USB charging cable, plug the iPhone into a computer and open the iTunes program.
Step 2: Open the Device Summary Page
Once the iPhone is connected, click on the phone icon that appears near the top-left corner of the iTunes window. This displays the device summary page.
Step 3: Restore the iPhone
Near the top of the device summary page, click the Restore iPhone button. Click Check in the pop-up dialogue box, then Restore and Update to confirm. The iPhone will download the latest update and reinstall the operating system.
Restoring the iPhone will delete all of the phone's contents. If you do not have a backup of your iPhone, click the Back Up Now button in the iTunes device summary page.
Find My iPhone must be turned off in order to restore the device. To turn off Find My iPhone, open the Settings application and select iCloud. Turn off the Find My iPhone slider and enter your Apple ID password to remove the setting.
Restore Through the Settings Application
Step 1: Open the Reset Section of the Settings App
Open the Settings application and select General. Scroll to the bottom of the screen and select Reset.
Step 2: Erase All Content and Settings
In the Reset section, select Erase All Content and Settings. Enter your iPhone Passcode if instructed. Select Erase iPhone and then Erase iPhone again to confirm the wipe. As with restoring through iTunes, Find My iPhone must be turned off in order to erase the device, and doing so erases all of the phone's contents.
Take the iPhone into an Apple Store
If none of these troubleshooting steps fix your frozen iPhone, there may be something mechanically wrong with the device. Make an appointment at an Apple corporate store and have one of their Geniuses diagnose the phone.