It's a cousin to UIImagePickerViewController that exposes just the basic video editing functionality from that class in a standalone, dedicated video editing view controller.
We'll download the video, rename it to something simple, and drag it into Xcode. We'll check the box next to our app in the dialog that appears, so it gets copied to our app target.
Here we've told it our path, and given it a 10 second max duration. (Pro Tip: Default is 10 minutes, set to 0 for no max).
From here we can simply present it like any other view controller:
present(editor,animated:true,completion:nil)
Neat!
The best part is all the functionality is self-contained inside the view controller.
The user can scrub through:
Trim the edges:
Then save the video back to the videoPath we set earlier:
Note:The documentation mentions UIVideoEditorController"only supporting Portrait"orientations, but it seems to work fine in all orientations.
Last but not least, we can (optionally) set a delegate on our UIVideoEditorController to get notified when the user saves or cancels (or a save fails):
UIReferenceLibraryViewController supports many different languages. New languages can be installed using the "Manage" option in the bottom-left:
Finally, it's worth noting that we get definition functionality for "free" in UITextFields via the "Look Up" item in the UIMenu that's shown when a user selects some text:
... and it's also worth noting that the view controller that appears when a user taps one of these "Look Up"menu items in a UITextField appears to be far more advanced than the what we get when presenting a plain ol' UIReferenceLibraryViewController:
The Dictionary results are still present, but we also get results across Music, Wikipedia, Movies, Websites, and even the App Store. Very cool.
(And nope, UIKit does not seem to provide a way to trigger this fancier view controller directly. Anyone interested in this should probably file a Radar.)
That's all for today. Those who want more UIKit B-Sides can check out these bites here.
UITextField is one of the sort of "low key" hidden gems of UIKit. Today we'll look at some of the lesser-known things it can do and how to configure them. Let's dive in.
We'll begin by creating a text field and customizing its look and feel. First, instead of boring plain placeholder, let's spice things up a bit:
Nice, now let's customize how our text field works.
Suppose we wanted to clear out its contents when a user tapped it. We simply set clearsOnBeginEditing to true.
Similarly, if we wanted to clear the contents not when the user tapped the field, but rather when the user began typing content, we can set clearsOnInsertion to true.
Let's add some more "padding" to our text field. This turns out to be a tricker than expected.
UITextField allows for customization of the rects it uses to draw text via subclassing:
We can get those awesome "swipe-to-reveal" actions from Mail.app in our own table views. We just need to implement one delegate function and return an array of UITableViewRowActions.
overridefunctableView(tableView:UITableView,editActionsForRowAtIndexPathindexPath:NSIndexPath)->[UITableViewRowAction]?{letdeployAction=UITableViewRowAction(style:.Default,title:"Deploy"){(action,indexPath)in// TODO: Deploy the troop at this indexPath.row}return[deployAction]}
Adjusting to State Transitions
We can override the willTransitionToState(state:) and didTransitionToState(state:)functions in our UITableViewCellsubclasses to run code when the cell begins or finishes showing the edit control or delete confirmation:
Today we'll begin looking at some lesser-known functionality inside UIKit. Some of these may be old news, but hopefully not all are.
We'll start with UIView. Let's flip it over and see what kind of b-side treasures we can find:
Subview Callbacks
We can override functions like didAddSubview(subview:) and willRemoveSubview(subview:) in our UIView subclasses. With this, we can take some action when subviews are added/removed.
An oldie, but a goodie. We can use the endEditing(force:)function to ask (or force) a view or any text fields inside it to resign as the first responder:
view.endEditing(true)
Custom Layer Class
We can specify a custom CALayer subclass for our UIView subclasses by overriding the layerClassfunction. This is great if our view needs to use CATiledLayer to scroll lots of content, or when building a camera preview view: