Skip to content

Instantly share code, notes, and snippets.

View zubco's full-sized avatar
🐾
-_-

Pavel Zubco zubco

🐾
-_-
View GitHub Profile
@veeneck
veeneck / Launch.swift
Last active July 7, 2017 13:54
Launch Trajectory in Swift and SpriteKit
/// Uses physics equations to calculate position of projectile at given time.
/// This tool is awesome to explain what's happening, and play with sample data:
/// http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html#tra6
func launchAtPoint(angle:CGFloat, start:CGPoint, end:CGPoint, node:SKNode) -> SKAction {
/// Constants
let gravity : Double = 9.8
let pixelsToMeters : CGFloat = 50
/// Calculate everything we can given an angle and an end point
@IanKeen
IanKeen / Example.swift
Last active July 10, 2019 22:02
Small utility methods to simplify dealing with Reusable items i.e. table/collection view cells
//`UITableViewCell` and `UICollectionViewCell` are `Reusable` by defaut
//Use the extension method to dequeue an instance of the appropriate `Reusable`
class MyVC: UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
tableView
.registerReusable(FooCell.self)
.registerReusable(BarCell.self)
}
@nicklockwood
nicklockwood / Hacking UIView Animation Blocks.md
Last active June 18, 2024 15:35
This article was originally written for objc.io issue 12, but didn't make the cut. It was intended to be read in the context of the other articles, so if you aren't familiar with concepts such as CALayer property animations and the role of actionForKey:, read the articles in that issue first.

Hacking UIView animation blocks for fun and profit

In this article, I'm going to explore a way that we can create views that implement custom Core Animation property animations in a natural way.

As we know, layers in iOS come in two flavours: Backing layers and hosted layers. The only difference between them is that the view acts as the layer delegate for its backing layer, but not for any hosted sublayers.

In order to implement the UIView transactional animation blocks, UIView disables all animations by default and then re-enables them individually as required. It does this using the actionForLayer:forKey: method.

Somewhat strangely, UIView doesn't enable animations for every property that CALayer does by default. A notable example is the layer.contents property, which is animatable by default for a hosted layer, but cannot be animated using a UIView animation block.