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” in iPhone Application Programming Guide.

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.

Simulate Hardware Keyboard

Toggles the software keyboard on an iPad simulator. Turn off the software keyboard to simulate using a keyboard dock or wireless keyboard with an iPad device.

Note: The Mac’s keyboard can be used as input into the simulator at all times.

iOS Uses Same Keyboard Layout As OS X

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

Force Low-Quality UIKit Effects

Simulates low-quality UIKit effects, so you can test that high-quality graphics display properly on lower-quality devices.

External Displays

Opens a window simulating a device’s TV Out signal.

Note: Several TV Out resolutions are available by choosing Hardware > TV Out > desired 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 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

In order 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 option, iOS Uses Same Keyboard Layout As OS X, selected, iOS simulator selects the keyboard that most closely matches the keyboard layout of your Mac. For most cases you want to leave this checked, but if you do feel a need to disable it—allowing you to select completely different keyboard layouts for your Mac and iOS Simulator—simply choose Hardware > 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 through 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.

To change a hardware keyboard layout in iOS Simulator

  1. Open Settings from the Home screen, and select General.

  2. Select Keyboard.

  3. Select Keyboards.

  4. Select the keyboard language you want to change the hardware layout for.

  5. Under Hardware Keyboard Layout, select the desired keyboard layout.

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 Hardware > Version > iOS version.

  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. Click the close button on the app you want to uninstall from the simulation environment.

  4. Click the Home button, or if the Home button is not visible, choose Hardware > Home to stop the icons from jiggling.

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, you need to save it to the Photos app first.

To save an image from a webpage to the Photos app

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

  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.

To copy an image in iOS Simulator

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

  2. Press and hold down the mouse button or trackpad on the image you want to copy.

    ../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.

    This copies the image to the Mac’s pasteboard. 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’s pasteboard. 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’s pasteboard to the simulator’s pasteboard.

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

  3. Double-click in 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’s pasteboard, 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 Macs, how it appears may differ between models. If you are using a computer whose screen is not large enough to display the entire simulator, only the screen of the simulated iOS device is shown, not the device border around it.

You can scale iOS Simulator by choosing Window > Scale > percentage of choice, but scaling shows only the device screen for any size other than 100 percent. For other scaling sizes, only the screen of the device is simulated, as shown in Figure 2-1.

Figure 2-1  iOS Simulator scaled to 100 percent (left) and 75 percent (right)

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 Retina display, your computer maps each point in the iOS app to a point on the Mac’s 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.