Skip to content

Instantly share code, notes, and snippets.

let square = UIView(frame: CGRect(x: 10, y: 10, width: 100, height: 100))
square.backgroundColor = .brown
self.view.addSubview(square)
let square = UIView(frame: CGRect(x: 10, y: 10, width: 100, height: 100))
square.backgroundColor = .brown
self.view.addSubview(square)
let timing = UICubicTimingParameters(animationCurve: .easeOut)
// A global animator variable is already defined
animator = UIViewPropertyAnimator(duration: 2.0, timingParameters:timing)
animator.addAnimations {
square.center = CGPoint(x: 300, y: square.center.y)
square.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
}
animator.startAnimation()
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:)))
self.view.addGestureRecognizer(panGesture)
@objc func handlePan(_ gesture: UIPanGestureRecognizer) {
let location = gesture.location(in: self.view)
// To figure out the fraction completed, take the x location of the touch,
// and divide it by the maximum x the finger can move to (which is the screen's width)
let fractionCompleted = location.x / self.view.bounds.width
// Changing this property changes the % complete of the animation.
// Try experimenting with a different fraction and see what you get
animator.fractionComplete = fractionCompleted
@cjinghong
cjinghong / eth-gas-prices.js
Last active May 2, 2022 17:15
ETH Gas Prices on Scriptable
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-blue; icon-glyph: gem;
const widget = new ListWidget()
// widget.setPadding(16,16,16,16)
const { widgetFamily, runsInWidget } = config
const isSmallWidget = runsInWidget
? widgetFamily === 'small'
: false // TO SIMULATE WIDGET SIZE WHEN ON DEBUG MODE
/**
##.......... ..........##
####.......... ...........####
#######.......... ..........#######
#########.......... ...........#########
###########.......... ..........###########
##########.......... ...........##########
###########.......... ..........###########
##########........... ...........##########
###########.......... ..........###########