Creating good-looking animations can be a lot of work. We could spend our whole day learning about curves and scaling, and transforms, and oh boy...
Instead, what if we could simply apply some popular animations to our UI elements with almost no effort at all? Today we'll check out a library called Spring that allows us to do just that.
Spring supplies a ton of common animations like shake, pop, squeeze, wobble, etc.
If we're using Interface Builder, we actually don't even need any code at all. We just use one of Spring'sUIView-subclasses, then we supply our animation by name.
In code, it's equally simple:
layer.animation="shake"layer.animate()
These all work great out of the box, but we can still customize the curve or individual properties if needed. Neat!
More info about Spring can be found at git.io/spring
Life needs limits. Whether its for usability reasons or maybe we're building the next Twitter, eventually we'll need to enforce a limit on how much content a user can enter into a UITextView. Let's take a look at how to do this.
We'll start by defining our limit as a global variable, making it easy to change later.
Next, we'll add a new UITextView to our view controller, and set ourselves as its delegate. (The text view's layout is handled off camera).
Finally, in the shouldChangeTextInRangedelegate function, we'll perform our checks.
We'll apply the proposed changes, and check if the resulting length is within our limits. The Bool we return describes if the change should be allowed.
And, we're done!
Update: March 28th, 6:15 PM
A previous version of this Bite contained an inferior implementation of the shouldChangeTextInRange: function. The one shown here comes from reader Filip Radelic. Thanks Filip!
A continued huge thanks to the folks at Hired.com for sponsoring this week's bites. Finding a good job can be a daunting task. Today we'll take a look at how we can use Hired.com to save our sanity, and find a great job in the process. Let's dive in.
We'll start by entering our email and answering some basic questions:
That's it. Hired will then work with over 3,000 pre-screened companies (both big and small) in 13 major metro areas (North America & Europe) to try find us a great job. Software engineers and designers on Hired can get 5+ job offers in a single week. Each offer will include salary and equity details upfront.
We can view interview requests and accept or reject them before talking to any company. If we get a job through Hired, they'll give us a $1,000 "thank you" bonus!
View offers and accept or reject them without talking to anyone.
Completely FREE + no obligations ever.
Hired is the real deal. They have solved some very real problems and fixed this historically messy process. Looking for a job? Don't waste time, sign up for Hired today so you can get back to work!
Our apps can do tons of useful things with users' data. Before we can though, we must always ask for their permission. Whether it's their physical location, photos, or contacts, the user is always in control of when and how we can access their data.
Each of these respective APIs has it's own way of asking the user if they will allow us to access the data within.
Today we'll check out a library called Permission that unifies all of these permission request into one beautiful API. Let's dive in.
We begin by declaring which piece of data we'd like access to:
letpermission:Permission=.Photos
At this point, permission.status will report .NotDetermined (as we'd expect). Next we'll request the permission, this is what causes the prompt to be presented to the user:
Permission is smart. If we request access to something the user has already said βno' to, it will present an alert (with customizable title/message/buttons) that allows the user to jump to the part of Settings.app needed to flip the switch back to βyes'.
Additionally, Permission also provides a PermissionSet type to do this on groups of permissions (i.e. Contacts + Camera + Photos).
There's also a PermissionButton (a UIButton subclass) that can display the current permission state, and prompt when tapped.
In-App Purchases have become a very important part of our business. Adding them to an app can involve quite a bit of boilerplate code though. Today we'll look at SwiftyStoreKit, a framework from Andrea Bizzotto that can help.
SwiftyStoreKit provides a few static functions we can use to easily implement all the common In-App Purchase tasks like getting the info about our "products" from Apple, purchasing, restoring, and even receipt verification. Let's take a look:
We pass in the product identifier, and supply a closure that can process the result. If successful, we use NSNumberFormatter (Bite #182) to print a nice looking summary of the product.
From here, we just need to wire up the other functions SwiftyStoreKit provides like purchaseProduct, restorePurchases, and verifyReceipt.
GIFs are amazing. They make us laugh, cry, and are the medium of choice for cat owners worldwide. π±
Unfortunately, GIFs can also be a bit of a headache when it comes to performance. Imagine an iOS app that displays a vertically scrolling list of animated GIFs. Making sure each of those GIFs is properly scaled, animating smoothly and handling memory well can be trickier than you might think.
Today we'll check out a library from Reda Lemeden called Gifu that aims to provide a high performance solution for this.
It's that simple! Under the hood, AnimatableImageView uses CADisplayLink. It will keep the current frame, as well as the next few frames in memory, ensuring we're good memory citizens. It ends up looking like this:
Gifu also provides a few functions (startAnimatingGIF, stopAnimatingGIF, and isAnimatingGIF) for controlling the actual animation. Nice.
Some libraries and frameworks provide large, far-reaching sets of tools for us to build our apps. Sometimes though, we just need a single component. Today we'll look at one such component that does one thing and one thing well: text views that adjust their height as a user types into them.
Then, we can use it as the inputAccessoryView of our view controller. This will cause it to be displayed when it becomes first responder. (Be sure to also return true from canBecomeFirstResponder too!)
self.inputAccessoryView=textView
NextGrowingTextView has a couple of properties for min/max number of allowed lines, but the real star is its robust delegatesproperty allowing us to set closures for all sorts of events:
A continued huge thanks to the folks at Hired.com for sponsoring this week's bites. Finding a good job can be a daunting task. Today we'll take a look at how we can use Hired.com to save our sanity, and find a great job in the process. Let's dive in.
We'll start by entering our email and answering some basic questions:
That's it. Hired will then work with over 3,000 pre-screened companies (both big and small) in 13 major metro areas (North America & Europe) to try find us a great job. Software engineers and designers on Hired can get 5+ job offers in a single week. Each offer will include salary and equity details upfront.
We can view interview requests and accept or reject them before talking to any company. If we get a job through Hired, they'll give us a $1,000 "thank you" bonus!
View offers and accept or reject them without talking to anyone.
Completely FREE + no obligations ever.
Hired is the real deal. They have solved some very real problems and fixed this historically messy process. Looking for a job? Don't waste time, sign up for Hired today so you can get back to work!
We've looked at allowing users to capture or choose images for use in our apps a couple times here. We learned about UIImagePickerController in Bite #83 and then ImagePicker in Bite #157.
Today we've got a new contender in this space called Fusuma. It's by Yuta Akizuki and aims to provide a very full-featured drop-in solution for this task. Let's try it.
We'll start by presenting the main FusumaViewController:
Getting people to download our app can be tough. It's important to do everything we can to help users get to our app in the App Store, with a chance to download. One great way we can do that is with Smart App Banners. Let's check βem out!
These are Smart App Banners. They essentially add a section to the top of a webpage in Safari on iOS that highlights an app. They display the icon, name, rating, price, and a button to view the app in the App Store.
Let's add one to our app's webpage.
All we need to do for the basic set of functionality is add a single metatag in the headtag of our page:
The first parameter, app-id, is the ID of our app on the App Store. We can find this in iTunes Connect.
The next bit is where things get more interesting: Smart App Banners know if a user already has an app installed.
We can provide a URL-Scheme URL so that if the user does happen to already have our app installed, they can jump directly to the content corresponding to where they were on the web.