Interacting with iOS Simulator

Interacting with iOS Simulator differs from interacting with an actual device. In this chapter you learn how to:

Simulating Hardware Interactions

With iOS Simulator, you can simulate most of the actions a user performs on a device. Table 2-1 lists hardware manipulations you can perform in iOS Simulator by using the Hardware menu.

Table 2-1  Manipulating iOS Simulator from the Hardware menu

Menu option

Hardware action

Rotate Left

Rotates the simulator to the left.

Rotate Right

Rotates the simulator to the right.

Shake Gesture

Simulates shaking the device.

Home

Displays the Home screen of the simulated device.

Lock

Displays the Lock screen.

Simulate Memory Warning

Sends the frontmost app a simulated low-memory warning.

For information on how to handle low-memory situations, see Observing Low-Memory Warnings.

Toggle In-Call Status Bar

Toggles the status bar between its normal state and its in-call state. This command shows how your app’s user interface looks when a user launches your app during a call or while navigation is running. The in-call state bar is used when a phone call is in progress, a FaceTime call is in progress, or Maps in iOS 6 is navigating. The status bar is taller in its in-call state than in its normal state.

Keyboard > iOS Uses Same Layout As OS X

Automatically selects the iOS keyboard that most closely matches the keyboard layout of your Mac.

Keyboard > Connect Hardware Keyboard

Toggles between using the Mac keyboard as input into the simulator. This option simulates using a keyboard dock or a wireless keyboard.

Keyboard > Toggle Software Keyboard

Toggles the presence of the onscreen software keyboard. This option is only available if a hardware keyboard is connected to the device.

External Displays

Opens a window simulating a device’s TV Out signal using the chosen resolution.

Simulating User Gestures

With iOS Simulator, you can perform traditional Multi-Touch gestures using the mouse and keyboard. Table 2-2 lists gestures you can perform in iOS Simulator. See iOS Human Interface Guidelines for more information about gestures.

Table 2-2  Performing gestures in iOS Simulator

Gesture

Desktop action

Tap

Click.

Touch and hold

Press and hold down the mouse button or trackpad.

Double-tap

Double-click.

Drag

Drag.

Swipe

Drag.

Flick

Drag quickly.

Two-finger drag

1. Place the pointer where you want the two-finger drag to occur.

2. Hold down the Option key.

3. Move the circles that represent finger touches to the start position.

4. Move the center of the pinch target by holding down the Shift key, moving the circles to the desired center position, and releasing the Shift key.

5. Hold down the Shift key and the mouse button, move the circles in the direction you want to drag, and release both the Shift key and the mouse button.

Pinch

1. Place the pointer where you want the pinch to occur.

2. Hold down the Option key.

3. Move the circles that represent finger touches to the start position.

4. Move the center of the pinch target by holding down the Shift key, moving the circles to the desired center position, and releasing the Shift key.

5. Hold down the mouse button, move the circles in and out to the end position, and release the Option key.

Rotate

1. Place the pointer where you want the rotation to occur.

2. Hold down the Option key.

3. Move the circles that represent finger touches to the start position.

4. Move the center of the pinch target by holding down the Shift key, moving the circles to the desired center position, and releasing the Shift key.

5. Hold down the mouse button, rotate the circles to the end position, and release the Option key.

Simulating Keyboards in iOS Simulator

For you to most accurately simulate a device on iOS Simulator, the simulator uses iOS keyboard layouts, as opposed to OS X keyboard layouts. If you have the iOS Uses Same Keyboard Layout As OS X option selected, iOS Simulator selects the keyboard that most closely matches the keyboard layout of your Mac. For most cases leave this option selected. However, if you do feel a need to disable it—allowing you to select completely different keyboard layouts for your Mac and iOS Simulator—choose Hardware > Keyboard > iOS Uses Same Keyboard Layout As OS X.

In addition to using the keyboard that most closely matches your Mac keyboard layout, you can also manually select a keyboard layout in the iOS Simulator settings. This approach can be helpful if you’re using a keyboard layout that iOS Simulator cannot automatically associate with a keyboard.

First set the hardware keyboard language to the development language and region—for example, select English (United States).

To set the hardware keyboard language and region

  1. From the Home screen, open Settings.

  2. Select General > Keyboard > Hardware Keyboard.

  3. Select the development language and region you want to use for the hardware keyboard.

Then add a new keyboard specifying the language and keyboard layout—for example, select French and Accented AZERTY.

To add a new keyboard

  1. From the Home screen, open Settings.

  2. Select General > Keyboard > Keyboards > Add New Keyboard.

  3. Select a language and a keyboard layout.

  4. Tap Done.

Set the hardware keyboard language to match the new keyboard language—for example, select French (Canada)—and test the new keyboard. For example, open your app and select the new keyboard when entering text as follows:

Installing and Uninstalling Apps

When you build your app for iOS Simulator, Xcode automatically installs it in the selected simulation environment. In the same way that the Maps app disappears when you switch from the 6.0 simulation environment to the 5.1 simulation environment, your own apps exist only within the specific simulation environments where you installed them.

To uninstall apps that you have installed in a simulation environment

  1. Select the simulation environment from which to remove the app by choosing a device from the Hardware > Devices menu.

  2. Place the pointer on the icon of the app you want to uninstall, and then press and hold down the mouse button or trackpad until the icons start to jiggle and a close button appears.

  3. To uninstall the app, click the close button on the app icon.

  4. In the dialog that appears, click Delete.

  5. To stop the icons from jiggling, press Shift-Command-H or choose Hardware > Home.

Copying and Pasting in iOS Simulator

iOS Simulator provides a variety of copy and paste operations, both within the simulator and between the simulator and your Mac. The actual copy and paste operations in iOS Simulator are performed in the same way they are on an iOS device, but if you are trying to copy and paste between the simulator and your Mac, additional steps must be taken. Copy and paste operations can be used on strings and images.

If you are copying an image from a webpage in iOS Simulator, save it to the Photos app first.

To save an image from a webpage to the Photos app

  1. Place the pointer on the image you want to save, and hold down the mouse button or trackpad.

  2. When the menu appears, click Save Image to save the image to the Photos app in iOS Simulator.

    ../Art/save_image_2x.png

    The image is saved to the Saved Photos album in the Photos app.

Alternatively, you can drag an image from the Finder on your Mac to iOS Simulator, and it will be saved to the Saved Photos album.

To copy an image in iOS Simulator

  1. Open the photo you want to copy in the Photos app.

  2. Place the pointer on the image you want to copy, and press and hold down the Command key and the mouse button or trackpad.

    ../Art/copy_image_2x.png
  3. Click Copy.

  4. If you intend to paste the image on your Mac outside of iOS Simulator, choose Edit > Copy instead.

    This copies the image to the Mac Clipboard. To paste the image in another app on the Mac, use that app’s Paste command.

To copy text in iOS Simulator

  1. Click the insertion point to display the selection buttons.

    ../Art/select_text_2x.png
  2. Click the Select button to select the adjacent word, or click Select All to select all text.

  3. Drag the grab points to select more or less text.

  4. Click Copy.

    ../Art/copy_text_2x.png
  5. If you are pasting the text on your Mac outside of iOS Simulator, choose Edit > Copy.

    This copies the text to the Mac Clipboard. To paste the text in another app on the Mac, use that app’s Paste command.

To paste text into iOS Simulator

  1. If the text you are pasting was copied from your Mac, choose Edit > Paste.

    This action copies the text from the Mac Clipboard to the simulator’s Clipboard.

  2. Navigate to the location where you want to paste the text you just copied.

  3. Double-click the location where you want to paste the text, and then click Paste.

    ../Art/paste_text_2x.png

Taking a Screenshot of the Simulator

In iOS Simulator you can copy a screenshot of the simulator to your Mac Clipboard, or you can save a copy of the screenshot as a file.

Viewing the Simulated Device’s Screen

Even though iOS Simulator runs on all Mac computers, how it appears may differ between models. If the resolution of the simulated device is too large for the iOS Simulator window to fit on your screen, scale iOS Simulator by choosing Window > Scale > percentage of choice.

Testing Retina and Non-Retina Display Devices

With iOS Simulator, you can simulate iOS devices both with and without Retina displays, regardless of whether you have a Mac with Retina display.

When working on a Mac without a Retina display, the simulator is mapped from pixel to pixel instead of from point to point. When simulating an app for an iOS device with Retina display on a Mac without a Retina display, the simulator appears twice as large as it would for a non-Retina display app to account for the extra pixels in a Retina display.

When working on a Mac with a Retina display, your computer maps each point in the iOS app to a point on the Mac screen. If the simulated app is for an iOS device with a Retina display, each point is composed of 1 pixel. If the app being simulated is for an iOS device without a Retina display, each point is composed of 2 pixels.

To learn more about mapping points to pixels, see Points Versus Pixels in Drawing and Printing Guide for iOS.