May 29, 2020 Macs Fan Control allows you to monitor and control almost any aspect of your computer's fans, with support for controlling fan speed, temperature sensors pane, menu-bar icon, and autostart with system option. Software solution to noise problems such as those caused by iMac HDD replacement, or overheating problems like those found on a MacBook Pro.
Professional DMX Lighting Control.
Mac Style.
Mac Style.
NEWVersion 3.3
Jun 01, 2017 Set the brightness of the display to a desired level. Your device will revert to its previous brightness setting/level once the app is closed. The only exception is for Zoom Room for Touch, which has limited controller features built into the touch screen. Zoom Rooms for Touch can function with or without a controller, but for full functionality, Zoom recommends pairing it with a controller. Note: There is a known issue with iOS 12 where the iPad will go to sleep when in Guided Access. Mar 19, 2016 Check for new drivers for your display: If every app on your display looks blurry, the display itself may need a driver update; check the Mac App Store’s Updates tab, or the manufacturer’s website for the latest driver software. Sometimes, an updated version of macOS may include drivers pre-installed, so always make sure macOS is up to date.
See what’s new
Highly Compatible.
Bring your own DMX interface: USB, Art-Net, sACN, or ESP-Net.Vastly Powerful.
Lightkey’s built-in FX engine takes your light show to a new level.Surprisingly Simple.
Easy to learn, quick to set up. Engineered exclusively for Mac.
Highly Compatible.
Bring Your Own DMX Interface.
Bring Your Own DMX Interface.
Save the cost of expensive proprietary DMX hardware: Lightkey works with a wide range of USB interfaces plus any Art-Net, sACN, or ESP-Net-compatible device, thanks to the Open Lighting Architecture. Whatever DMX interface you have, there’s a good chance that Lightkey supports it—simply download Lightkey for free, plug in your interface, and give it a try.
Choose from a wide range of USB–DMX interfaces from various manufacturers
Or use any Art-Net, sACN, or ESP Net network interface
+Show Supported Interfaces×Hide Interfaces
Hardware Control.
Enhance Your Experience.
Enhance Your Experience.
Do you prefer the physical controls on a lighting console? Then you can have the best of both worlds. Lightkey integrates seamlessly with any standard MIDI controller and DMX console (through DMX-In). You can map each hardware control to whatever feature you like and build your own custom-tailored show control desk to trigger cues, presets and sequences, adjust fixture properties, tap the beat, and whatever else you need.
Designed for Creativity.
Take Your Light Show to a New Level.
Take Your Light Show to a New Level.
Designed for the needs of creative lighting designers, Lightkey breaks free from the old thinking about DMX values and channels. Thru advanced fixture profiles it understands all your fixtures’ properties—like Color, Gobo, Shutter, Prism, Zoom—, and provides specially-designed, easy-to-use controls for each of them. The current state of your fixtures is always visible in the live preview. Simply concentrate on the perfect light show and let Lightkey translate it to the proper DMX values.
Virtual Light Beams
Virtual light beams show your lights’ real-world positions and also reflect intensity, color, focus, zoom, iris, frost, shutter/strobe, and prism states.Built-In Stage Editor
The built-in graphical editor lets you recreate the stage or dance floor on the screen. Apart from your fixtures you can add shapes, trusses, and custom images.Copy & Paste
Easily copy and paste properties and effects between fixtures – even fixtures of different types. Of course, you can undo as well.At a Glance
Little “bubbles” in the Preview show you at a glance which fixture properties are overridden or defined by a preset, sequence, or cue.On-the-Fly Changes
Quickly change any fixture property on the fly—perfect for nightclubs and parties where you don’t have a song run sheet in advance.Intelligent Design View
The Design view automatically adapts itself according to your fixtures and their properties so you only see the controls you really need.
Real-World Pan/Tilt Locations
Lightkey knows your moving light’s pan/tilt range, home position, and rotation direction. With this information it calculates the exact beam position on the stage or dance floor, so the preview always shows the fixture’s real-world position, letting you point your lights wherever you like with just a single mouse click. Even if you select multiple devices from different manufacturers, Lightkey will calculate the individual DMX values for each of them so they all point in the same direction.Effects.
Infinite Possibilities.
Infinite Possibilities.
Lightkey’s powerful effects engine makes it easy and fun to create amazing dynamic looks. Choose from over 50 effect templates or create your own pattern, curve, or movement effects. Effects can be applied to almost any fixture property and stored in presets and cues while staying editable all the time. Apply effects to multi-beam LED strips and matrixes. Synchronize effects to music. Overlay multiple effects for countless possibilities.
improved
Beat Control.
Stay in the rhythm.
Stay in the rhythm.
Effortlessly sync your light show to music. Lightkey connects to your DAW, DJ app, or audio analysis software through MIDI Clock or Ableton Link. Or simply tap the beat and Lightkey will continue at the same tempo. You can adjust the speed of individual cues at any time with a Beat Multiplier.
Tap the Beat
Tap the beat with the mouse, keyboard, or a MIDI controller, and Lightkey will pick up the tempo.MIDI Clock
Receive a MIDI Beat Clock signal sent by a DJ software, mixer, or audio analysis tool.Ableton Link
Ableton Link syncs beat information between apps on the same computer or local network.
Always in Sync.
Run Your Lighting From Ableton Live.
Run Your Lighting From Ableton Live.
The unique Live Triggers feature makes it quick and intuitive to trigger lighting cues directly from Ableton Live: Simply drag cues you created in Lightkey to the Ableton Live timeline. If you’re a live performer, you can create a light show that’s perfectly in sync with the music without any manual operation during the show.
Setup.
Surprisingly Simple.
Surprisingly Simple.
An interactive assistant guides you through the entire setup process: Configure DMX output, patch your fixtures, create a visual representation of the stage. And if you ever need a fixture profile that is not in the built-in library, simply send us the DMX specs and we’ll create it for you within a few days.
Live Preview
This 2D view of your lighting rig shows the current state of the fixtures with virtual light beams
This 2D view of your lighting rig shows the current state of the fixtures with virtual light beams
Preset Palette
Create and organize presets and sequences
Create and organize presets and sequences
Control panel
Build a custom-tailored control panel with buttons and faders to control your lights during a show
Build a custom-tailored control panel with buttons and faders to control your lights during a show
Shortcuts
Shows keyboard shortcuts and gestures for the current context
Shows keyboard shortcuts and gestures for the current context
Command Central.
Don’t waste your time shuffling windows and panels around. Everything you need is cleanly arranged in a single window, providing you with exactly the controls you need at any time. The elegant, white-on-dark UI has been specially designed for use in low-light environments—it even adapts itself to the light colors.
Full-Screen Mode
The single-window user interface has been specially designed for full-screen mode.Touch Screen Support
All controls have large clickable areas and work great with touch screens.Multi-Touch Gestures
Pinch, swipe, scroll, force click: With a Multi-Touch trackpad you can change fixture properties in a natural way. (And it’s fun too.)Extensive Keyboard Shortcuts
A clever, well-structured, and extensible system of keyboard shortcuts lets you control virtually every application feature.
Open User GuideLightkey User Guide.Take an in-depth look.
Fixtures.
State of the Art.
State of the Art.
Lightkey handles even the most sophisticated fixtures with ease. Its smart fixture profiles support multiple modes (“personalities”), 16-bit output, conditional properties, RGB/CMY color mixing, multiple color and gobo wheels, custom beam layouts, and much more. Lightkey comes with a huge library of over 3000 high-quality fixture profiles for all popular manufacturers, and it can import thousands of freely available profiles in the formats SSL2, FXT, and PFF.
Built-In Fixture Editor
To make fixture profile creation as easy as possible, Lightkey’s fixture editor has the same layout as a typical DMX chart. (Click the image for a side-by-side comparison.) And it’s built right into the application so changes take effect instantly.
Lightkey’s fixture editor (right) has the same layout as a typical DMX chart (left).
High Technology.
Made for Your Mac.
Made for Your Mac.
Lightkey was engineered from the ground up as a native Mac app, so it’s finally goodbye to the Windows emulation. It perfectly matches your Mac’s look and feel and comes with all the familiar features like Dark Mode, full screen view, autosaving, copy and paste, unlimited undo, or automatic updates. Under the hood, Lightkey takes full advantage of your Mac’s capabilities including 64-bit processing, multicore computing thru Grand Central Dispatch, support for Retina displays, and pristine graphics using Apple’s Core Animation and Metal 2 technologies.
Pristine Retina graphics
powered by Metal 2
powered by Metal 2
Ps3 Controller App Free
Haptic feedback, multi-touch gestures and force click
Editions & Pricing.What’s your Lightkey edition?
Simply determine how many output channels you need.- All editions come with the full feature set, even the free edition.
- You can always upgrade if you need more channels later.
Output Channels | 256 | 1024 |
Price in US Dollars | $ 69per year | $ 179per year |
USB Output | ||
Art-Net Output | ||
sACN Output | ||
ESP-Net Output | ||
Live Triggers | ||
DMX Input | ||
MIDI Input | ||
Free Tech Support |
Check it Out.
Today. For Free.
Today. For Free.
Download Lightkey today and see for yourself. It’s free, easy, and a great deal of fun.
Download LightkeyWhat You Need
Lightkey uses the Open Lighting Architecture, an open-source framework by the Open Lighting Project.
Download the source code here or get the latest version on GitHub.
Download the source code here or get the latest version on GitHub.
Work with View Controllers
In this lesson, you’ll continue to work on the user interface (UI) for the meal scene in the FoodTracker app. You’ll add an image view to the scene, and use an image picker to let the user select an image for the meal.
Learning Objectives
At the end of the lesson, you’ll be able to:
- Understand the view controller life cycle and its callbacks (for example,
viewDidLoad
,viewWillAppear
andviewDidAppear
) - Pass data between view controllers
- Dismiss a view controller
- Use gesture recognizers to generate events
- Anticipate object behavior based on the
UIView
/UIControl
class hierarchy - Use the asset catalog to add image assets to a project
Understand the View Controller Lifecycle
So far, the FoodTracker app has a single scene, whose user interface is managed by a single view controller. As you build more complex apps, you’ll create more scenes, and will need to manage loading and unloading views as they’re moved on and off the screen.
An object of the
UIViewController
class (and its subclasses) comes with a set of methods that manage its view hierarchy. iOS automatically calls these methods at appropriate times when a view controller transitions between states. When you create a view controller subclass (like the ViewController
class you’ve been working with), it inherits the methods defined in UIViewController
and lets you add your own custom behavior for each method. It’s important to understand when the system calls these methods, so you can set up or tear down the views you’re displaying at the appropriate step in the process—something you’ll need to do later in the lessons. iOS calls the
UIViewController
methods as follows:viewDidLoad()
—Called when the view controller’s content view (the top of its view hierarchy) is created and loaded from a storyboard. The view controller’s outlets are guaranteed to have valid values by the time this method is called. Use this method to perform any additional setup required by your view controller.Typically, iOS callsviewDidLoad()
only once, when its content view is first created; however, the content view is not necessarily created when the controller is first instantiated. Instead, it is lazily created the first time the system or any code accesses the controller’sview
property.viewWillAppear()
—Called just before the view controller’s content view is added to the app’s view hierarchy. Use this method to trigger any operations that need to occur before the content view is presented onscreen. Despite the name, just because the system calls this method, it does not guarantee that the content view will become visible. The view may be obscured by other views or hidden. This method simply indicates that the content view is about to be added to the app’s view hierarchy.viewDidAppear()
—Called just after the view controller’s content view has been added to the app’s view hierarchy. Use this method to trigger any operations that need to occur as soon as the view is presented onscreen, such as fetching data or showing an animation. Despite the name, just because the system calls this method, it does not guarantee that the content view is visible. The view may be obscured by other views or hidden. This method simply indicates that the content view has been added to the app’s view hierarchy.viewWillDisappear()
—Called just before the view controller’s content view is removed from the app’s view hierarchy. Use this method to perform cleanup tasks like committing changes or resigning the first responder status. Despite the name, the system does not call this method just because the content view will be hidden or obscured. This method is only called when the content view is about to be removed from the app’s view hierarchy.viewDidDisappear()
—Called just after the view controller’s content view has been removed from the app’s view hierarchy. Use this method to perform additional teardown activities. Despite the name, the system does not call this method just because the content view has become hidden or obscured. This method is only called when the content view has been removed from the app’s view hierarchy.
You’ll be using some of these methods in the FoodTracker app to load and display your data. In fact, if you recall, you’ve already written some code in the
viewDidLoad()
method of ViewController
:overridefuncviewDidLoad() {
super.viewDidLoad()
// Handle the text field’s user input through delegate callbacks.
nameTextField.delegate = self
}
This style of app design where view controllers serve as the communication pipeline between your views and your data model is known as MVC (Model-View-Controller). In this pattern, models keep track of your app’s data, views display your user interface and make up the content of an app, and controllers manage your views. By responding to user actions and populating views with content from the data model, controllers serve as a gateway for communication between the model and views. MVC is central to a good design for any iOS app, and so far, the FoodTracker app has been built along MVC principles.
As you keep the MVC pattern in mind for rest of the app’s design, it’s time to take your basic user interface to the next level, and add an image to the meal scene.
Add a Meal Photo
The next step in finishing the meal scene is adding a way to display a photo of a particular meal. For this, you’ll use an image view (
UIImageView
), a user interface element that displays a picture.To add an image view to your scene
- Open your storyboard,
Main.storyboard
. - Open the Object library in the utility area. (Alternatively, choose View > Utilities > Show Object Library.)
- In the Object library, type
image view
in the filter field to find the Image View object quickly. - Drag an Image View object from the Object library to your scene so that it’s in the stack view below the button.
- With the image view selected, open the Size inspector in the utility area.Recall that the Size inspector appears when you select the fifth button from the left in the inspector selector bar. It lets you edit the size and position of an object in your storyboard.
- In the Intrinsic Size field, select Placeholder. (This field is at the bottom of the Size inspector, so you’ll need to scroll down to it.)
- Type
320
in both the Width and Height fields. Press Return.A view’s intrinsic content size is the preferred size for the view based on its content. An empty image view doesn’t have an intrinsic content size. As soon as you add an image to a view, its intrinsic content size is set to the image’s size. Providing a placeholder size gives the image a temporary intrinsic content size that you can use while designing your user interface. This value is only used while designing your interface in Interface Builder; at runtime, the layout engine uses the view’s actual intrinsic content size instead. - On the bottom right of the canvas, open the Pin menu.
- Select the checkbox next to Aspect Ratio.
- In the Pin menu, click the Add 1 Constraints button.Your image view now has a 1:1 aspect ratio, so it will always be a square.
- With the image view selected, open the Attributes inspector .Recall that the Attributes inspector appears when you select the fourth button from the left in the inspector selector bar. It lets you edit the properties of an object in your storyboard.
- In the Attributes inspector, find the Interaction field and select the User Interaction Enabled checkbox.You’ll need this feature later to let users interact with the image view.
Display a Default Photo
Add a placeholder image to let users know that they can interact with the image view to select a photo. Use this image from the
Images/
folder of the downloadable file at the end of this lesson, or use your own image.To add an image to your project
- In the project navigator, select
Assets.xcassets
to view the asset catalog.The asset catalog is a place to store and organize your image assets for an app. - In the bottom left corner, click the plus (
+
) button and select New Image Set from the pop-up menu. - Double-click the image set name and rename it to
defaultPhoto
. - On your computer, select the image you want to add.
- Drag and drop the image into the
2x
slot in the image set.2x
is the display resolution for the iPhone 7 Simulator that you’re using in these lessons, so the image will look best at this resolution.Explore FurtherFor more information on image resolutions, see Graphics > Image Size and Resolution in iOS Human Interface Guidelines.
With the default placeholder image added to your project, set the image view to display it.
To display a default image in the image view
- Open your storyboard.
- In your storyboard, select the image view.
- With the image view selected, open the Attributes inspector in the utility area.
- In the Attributes inspector, find the field labeled Image and select
defaultPhoto
.
Checkpoint: Run your app. The default image displays in the image view.
Connect the Image View to Code
Now, you need to implement the functionality to change the image in this image view at runtime. First, you need to connect the image view to the code in
ViewController.swift
.To connect the image view to the ViewController.swift code
- Click the Assistant button in the Xcode toolbar near the top right corner of Xcode to open the assistant editor.
- If you want more space to work, collapse the project navigator and utility area by clicking the Navigator and Utilities buttons in the Xcode toolbar.You can also collapse the outline view.
- In your storyboard, select the image view.
- Control-drag from the image view on your canvas to the code display in the editor on the right, stopping the drag at the line just below the existing outlets in
ViewController.swift
. - In the dialog that appears, for Name, type
photoImageView
. Leave the rest of the options as they are. - Click Connect.Xcode adds the necessary code to
ViewController.swift
to store a reference to the image view and configures the storyboard to set up that connection.
You can now access the image view from code to change its image, but how do you know when to change the image? You need to give users a way to indicate that they want to change the image—for example, by tapping the image view. Then, you’ll define an action method to change the image when a tap occurs.
There’s a nuanced distinction between views and controls, which are specialized versions of views that respond to user actions in a specific way. A view displays content, whereas a control is used to modify the content in some way. A control (
UIControl
) is a subclass of UIView
. In fact, you’ve already worked with both views (labels, image views) and controls (text fields, buttons) in your interface.Create a Gesture Recognizer
An image view isn’t a control, so it’s not designed to respond to input in the same way that button or a slider might. For example, you can’t simply create an action method that’s triggered when a user taps on an image view. (If you try to Control-drag from the image view to your code, you’ll notice that you can’t select Action in the Connection field.)
Fortunately, it’s quite easy to give a view the same capabilities as a control by adding a gesture recognizer to it. Gesture recognizers are objects that you attach to a view that allow the view to respond to the user the way a control does. Gesture recognizers interpret touches to determine whether they correspond to a specific gesture, such as a swipe, pinch, or rotation. You can write an action method that is called when a gesture recognizer recognizes its assigned gesture, which is exactly what you need to do for the image view.
Attach a tap gesture recognizer (
UITapGestureRecognizer
) to the image view, which will recognize when a user has tapped the image view. You can do this easily in your storyboard.To add a tap gesture recognizer to your image view
- Open the Object library (Choose View > Utilities > Show Object Library).
- In the Object library, type
tap gesture
in the filter field to find the Tap Gesture Recognizer object quickly. - Drag a Tap Gesture Recognizer object from the Object library to your scene, and place it on top of the image view.The Tap Gesture Recognizer object appears in the meal scene dock.
Connect the Gesture Recognizer to Code
Now, connect that gesture recognizer to an action method in your code.
To connect the gesture recognizer to the ViewController.swift code
- Control-drag from the gesture recognizer in the scene dock to the code display in the editor on the right, stopping the drag at the line below the
//MARK: Actions
comment inViewController.swift
. - In the dialog that appears, for Connection, select Action.
- For Name, type
selectImageFromPhotoLibrary
. - For Type, select
UITapGestureRecognizer
.In Disk Utility select the key drive, click on the Erase tab, and from the Format pop-up menu choose Mac OS Extended (Journaled). Downgrading software on mac from sierra to snow leopard video. - Click Connect.Xcode adds the necessary code to
ViewController.swift
to set up the action.@IBActionfuncselectImageFromPhotoLibrary(_sender: UITapGestureRecognizer) {
}
Create an Image Picker to Respond to User Taps
When a user taps the image view, they should be able to choose a photo from a collection of photos, or take one of their own. Fortunately, the
UIImagePickerController
class has this behavior built into it. An image picker controller manages the user interface for taking pictures and for choosing saved images to use in your app. And just as you need a text field delegate when you work with a text field, you need an image picker controller delegate to work with an image picker controller. The name of that delegate protocol is UIImagePickerControllerDelegate
, and the object that you’ll define as the image picker controller’s delegate is ViewController.
First,
ViewController
needs to adopt the UIImagePickerControllerDelegate
protocol. Because ViewController
will be in charge of presenting the image picker controller, it also needs to adopt the UINavigationControllerDelegate
protocol, which simply lets ViewController
take on some basic navigation responsibilities.To adopt the UIImagePickerControllerDelegate and UINavigationControllerDelegate protocols
- Return to the standard editor by clicking the Standard button.Expand the project navigator and utility area by clicking the Navigator and Utilities buttons in the Xcode toolbar.
- In the project navigator, select
ViewController.swift
. - In
ViewController.swift
, find theclass
line, which should look like this:classViewController: UIViewController, UITextFieldDelegate {
- After
UITextFieldDelegate
, add a comma (,
) andUIImagePickerControllerDelegate
to adopt the protocol.classViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate {
- After
UIImagePickerControllerDelegate
, add a comma (,
) andUINavigationControllerDelegate
to adopt the protocol. Quickest way to launch app on mac.classViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
At this point, you can go back to the action method you defined,
selectImageFromPhotoLibrary(_:)
, and finish its implementation.To implement the selectImageFromPhotoLibrary(_:) action method
- In
ViewController.swift
, find theselectImageFromPhotoLibrary(_:)
action method you added earlier.It should look like this:@IBActionfuncselectImageFromPhotoLibrary(_sender: UITapGestureRecognizer) {
}
- In the method implementation, between the curly braces (
{}
), add this code:// Hide the keyboard.
nameTextField.resignFirstResponder()
This code ensures that if the user taps the image view while typing in the text field, the keyboard is dismissed properly. - Add this code to create an image picker controller:
// UIImagePickerController is a view controller that lets a user pick media from their photo library.
letimagePickerController = UIImagePickerController()
- Add this code:
// Only allow photos to be picked, not taken.
imagePickerController.sourceType = .photoLibrary
This line of code sets the image picker controller’s source, or the place where it gets its images. The.photoLibrary
option uses the simulator’s camera roll.The type ofimagePickerController.sourceType
is known to beUIImagePickerControllerSourceType
, which is an enumeration. This means you can write its value as the abbreviated form.photoLibrary
instead ofUIImagePickerControllerSourceType.photoLibrary
. Recall that you can use the abbreviated form anytime the enumeration value’s type is already known. - Add this code to set the image picker controller’s delegate to
ViewController
:// Make sure ViewController is notified when the user picks an image.
imagePickerController.delegate = self
- Below the previous line, add this line of code:
present(imagePickerController, animated: true, completion: nil)
present(_:animated:completion:)
is a method being called onViewController
. Although it’s not written explicitly, this method is executed on an implicitself
object. The method asksViewController
to present the view controller defined byimagePickerController
. Passingtrue
to theanimated
parameter animates the presentation of the image picker controller. Thecompletion
parameter refers to a completion handler, a piece of code that executes after this method completes. Because you don’t need to do anything else, you indicate that you don’t need to execute a completion handler by passing in nil.
Your
selectImageFromPhotoLibrary(_:)
action method should look like this:@IBActionfuncselectImageFromPhotoLibrary(_sender: UITapGestureRecognizer) {
// Hide the keyboard.
nameTextField.resignFirstResponder()
// UIImagePickerController is a view controller that lets a user pick media from their photo library.
letimagePickerController = UIImagePickerController()
// Only allow photos to be picked, not taken.
imagePickerController.sourceType = .photoLibrary
// Make sure ViewController is notified when the user picks an image.
imagePickerController.delegate = self
present(imagePickerController, animated: true, completion: nil)
}
After an image picker controller is presented, you interact with it through the delegate methods. To give users the ability to select a picture, you’ll need to implement two of the delegate methods defined in
UIImagePickerControllerDelegate
:funcimagePickerControllerDidCancel(_picker: UIImagePickerController)
funcimagePickerController(_picker: UIImagePickerController, didFinishPickingMediaWithInfoinfo: [String : Any])
The first of these,
imagePickerControllerDidCancel(_:)
, gets called when a user taps the image picker’s Cancel button. This method gives you a chance to dismiss the UIImagePickerController
(and optionally, do any necessary cleanup).To implement the imagePickerControllerDidCancel(_:) method
- In
ViewController.swift
, right above the//MARK: Actions
section, add the following:This is a comment to help you (and anybody else who reads your code) navigate through your code and identify that this section applies to the image picker implementation. - Below the comment you just added, add the following method:
funcimagePickerControllerDidCancel(_picker: UIImagePickerController) {
}
- In this method, add the following line of code:
// Dismiss the picker if the user canceled.
dismiss(animated: true, completion: nil)
This code animates the dismissal of the image picker controller.
Your
imagePickerControllerDidCancel(_:)
method should look like this:funcimagePickerControllerDidCancel(_picker: UIImagePickerController) {
// Dismiss the picker if the user canceled.
dismiss(animated: true, completion: nil)
}
The second
UIImagePickerControllerDelegate
method that you need to implement, imagePickerController(_:didFinishPickingMediaWithInfo:)
, gets called when a user selects a photo. This method gives you a chance to do something with the image or images that a user selected from the picker. In your case, you’ll take the selected image and display it in your image view.To implement the imagePickerController(_:didFinishPickingMediaWithInfo:) method
- Below the
imagePickerControllerDidCancel(_:)
method, add the following method:funcimagePickerController(_picker: UIImagePickerController, didFinishPickingMediaWithInfoinfo: [String : Any]) {
}
- In this method, add the following line of code:
// The info dictionary may contain multiple representations of the image. You want to use the original.
guardletselectedImage = info[UIImagePickerControllerOriginalImage] as? UIImageelse {
fatalError('Expected a dictionary containing an image, but was provided the following: (info)')
}
Theinfo
dictionary always contains the original image that was selected in the picker. It may also contain an edited version of that image, if one exists. To keep things simple, you’ll use the original, unedited image for the meal photo.This code accesses the original, unedited image from theinfo
dictionary. It safely unwraps the optional returned by the dictionary and casts it as aUIImage
object. The expectation is that the unwrapping and casting operations will never fail. If they do, it represents either a bug in your app that needs to be fixed at design time. ThefatalError()
method logs an error message to the console, including the contents of theinfo
dictionary, and then causes the app to terminate—preventing it from continuing in an invalid state. - Add this line of code to set the selected image in the image view outlet that you created earlier:
// Set photoImageView to display the selected image.
photoImageView.image = selectedImage
- Add the following line of code to dismiss the image picker:
// Dismiss the picker.
dismiss(animated: true, completion: nil)
Your
imagePickerController(_:didFinishPickingMediaWithInfo)
method should look like this:funcimagePickerController(_picker: UIImagePickerController, didFinishPickingMediaWithInfoinfo: [String : Any]) {
// The info dictionary may contain multiple representations of the image. You want to use the original.
guardletselectedImage = info[UIImagePickerControllerOriginalImage] as? UIImageelse {
fatalError('Expected a dictionary containing an image, but was provided the following: (info)')
}
// Set photoImageView to display the selected image.
photoImageView.image = selectedImage
// Dismiss the picker.
dismiss(animated: true, completion: nil)
}
Checkpoint: Run your app. What happens when you click on the image view?
The app terminates with a
SIGABRT
signal. This means an error occurred that was serious enough to cause the app to abort. In this case, the problem occurs when you attempt to present the image picker. The system must ask the user for permission before accessing their photo library. In iOS 10 and later, you must provide a photo library usage description. This description explains why your app wants to access the photo library.To add a photo library usage description
- In the project navigator, select
Info.plist
.Xcode displays the property list editor in the editor area. A property list is a structured text file that contains essential configuration information about your app. The root of the property list is a dictionary that holds a set of predefined keys and their values.Explore FurtherFor more information on possibleinfo.plist
keys, see Information Property List Key Reference. - If the last item in the property list is an array, make sure the array is collapsed. If you add an item to an expanded array, it adds a child item. If you add an item to a collapsed array, it adds a sibling to the array.
- To add a new item, hover over the last item in the property list, and click on the add button when it appears (or select Editor > Add Item).
- In the pop-up menu, scroll down and choose Privacy - Photo Library Usage Description.
- In the new row, make sure the Type is set to String. Then, double-click on the Value section and enter
Allows you to add photos to your meals.
- Press the Return key when you are done editing the description string.
Checkpoint: Run your app again. This time you should be able to click the image view to pull up an image picker. You’ll need to click OK on the alert that asks for permission to give the FoodTracker app access to Photos. Then, you can click the Cancel button to dismiss the picker, or open Camera Roll and click an image to select it and set it as the image in the image view.
If you look through the photos available in the simulator, you’ll notice that it doesn’t include any photos of food. You can add your own images directly into the simulator to test the FoodTracker app with appropriate sample content. You can find a sample image within the
Images/
folder of the downloadable file at the end of this lesson, or use your own image.To add images to iOS Simulator
- If necessary, run your app in the simulator.
- On your computer, select the images you want to add.
- Drag and drop the images into the simulator.The simulator opens the Photos app and shows the images you added.
Best Game Controller For Mac
Checkpoint: Run your app. You should be able to tap the image view to pull up an image picker. Open Camera Roll, and click one of the images you added to the simulator to select it and set it as the image in the image view.
Ps3 Controller App Free Download
Wrapping Up
In this lesson, you’ve learned about the view controller life cycle methods, and used them to configure your view controller’s content. You’ve also learned how to add gesture recognizers to a view, and how to select photos from the photo library. The scene is starting to look like a real app. In the next lesson, you’ll add a custom control to the scene.
Note
To see the completed sample project for this lesson, download the file and view it in Xcode.
Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-12-08