Skip to content

Instantly share code, notes, and snippets.

View Stickerbox's full-sized avatar

Jordan Dixon Stickerbox

View GitHub Profile
@Stickerbox
Stickerbox / UIView+Animations
Created November 30, 2017 11:19
A collection of simple UIView animations in Swift
//
// Created by Jordan.Dixon on 30/11/2017.
// Copyright © 2017 Jordan.Dixon. All rights reserved.
//
import UIKit
// MARK: Paralax effect
internal extension UIView {
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mubaloo.custview.CustView
android:id="@+id/customView"
android:layout_width="0dp"
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
customView.buttonTapped = {
println("button was tapped")
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
class CustView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
: ConstraintLayout(context, attrs, defStyleAttr) {
var buttonTapped: (() -> Unit)? = null
init {
val view = LayoutInflater.from(context).inflate(R.layout.custom_view, this, false)
val set = ConstraintSet()
addView(view)
class MainActivity : AppCompatActivity() {
var hasAnimated = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onTouchEvent(event: MotionEvent?): Boolean {
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/label"
extension CAShapeLayer {
func drawCircle(in rect: CGRect, with configuration: PathConfiguration) {
let center = CGPoint(x: rect.maxX / 2, y: rect.maxY / 2)
let longestSide = rect.height < rect.width ? rect.height : rect.width
let circularPath = UIBezierPath(arcCenter: center, radius: (longestSide / 2) - (configuration.lineWidth / 2), startAngle: configuration.startAngle, endAngle: 2 * CGFloat.pi, clockwise: true)
import UIKit
extension CAShapeLayer {
func drawCircle(in rect: CGRect, with configuration: PathConfiguration) {
let center = CGPoint(x: rect.maxX / 2, y: rect.maxY / 2)
let longestSide = rect.height < rect.width ? rect.height : rect.width