Skip to content

Instantly share code, notes, and snippets.

View aceontech's full-sized avatar

Alex Manarpies aceontech

View GitHub Profile
@vinczebalazs
vinczebalazs / SheetModalPresentationController.swift
Last active July 21, 2024 15:36
A presentation controller to use for presenting a view controller modally, which can be dismissed by a pull down gesture. The presented view controller's height is also adjustable.
import UIKit
extension UIView {
var allSubviews: [UIView] {
subviews + subviews.flatMap { $0.allSubviews }
}
func firstSubview<T: UIView>(of type: T.Type) -> T? {
allSubviews.first { $0 is T } as? T
anonymous
anonymous / debounce.swift
Created July 9, 2016 07:54
debounce in Swift 3
func debounce(delay: Int, queue: DispatchQueue, action: (()->()) ) -> ()->() {
var lastFireTime = DispatchTime.now()
let dispatchDelay = DispatchTimeInterval.seconds(delay)
return {
lastFireTime = DispatchTime.now()
let dispatchTime: DispatchTime = lastFireTime + dispatchDelay
queue.after(when: dispatchTime) {
let when: DispatchTime = lastFireTime + dispatchDelay
let now = DispatchTime.now()
@krodak
krodak / UIViewController+TabBarAnimations
Last active March 3, 2018 19:15
UIViewController extension for hidding UITabBarController
import UIKit
extension UIViewController {
func setTabBarVisible(visible:Bool, animated:Bool) {
//* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time
// bail if the current state matches the desired state
if (tabBarIsVisible() == visible) { return }
@robertjpayne
robertjpayne / SwiftStaticCompile.rb
Last active April 23, 2017 15:40
A ruby function to generate a static library + clang module from a single Swift source file
require "Subprocess"
require "tmpdir"
#
# Currently will only convert a single swift code file into a static library
# and cannot include any Objective-C code.
#
# Usage: generate("/path/to/MyCode.swift", :ios)
#
def generate(file, platform, dst=nil)
@schpaa
schpaa / gist:d1ad2feddd900ed70c06
Last active February 9, 2016 09:20
Constraints registering in Swift
import Cocoa
struct Constraint {
typealias T = (attribute: CAConstraintAttribute, relativeTo:String, relatedAttribute: CAConstraintAttribute, offset: CGFloat)
let data: T
func create() -> CAConstraint {
let newConstraint: AnyObject! = CAConstraint.constraintWithAttribute(data.attribute, relativeTo: data.relativeTo, attribute: data.relatedAttribute, offset: data.offset)
return newConstraint as CAConstraint
}
@mbigatti
mbigatti / UIView+FirstResponder.swift
Created July 10, 2014 15:40
A classical first responder finder using Swift.
import UIKit
extension UIView {
func currentFirstResponder() -> UIResponder? {
if self.isFirstResponder() {
return self
}
for view in self.subviews {
if let responder = view.currentFirstResponder() {
@RuiAAPeres
RuiAAPeres / gist:11402456
Last active August 29, 2015 14:00
Sam Page's SparkRecording Implementation with Facebook's Pop
//The calculations are coming from [here](https://gist.github.com/d-ronnqvist/11266321) (thanks David!)
- (void)updateAnimations
{
CGFloat duration = self.duration * (1.f - [[self.progressLayers firstObject] strokeEnd]);
CGFloat strokeEndFinal = 1.f;
for (CAShapeLayer *progressLayer in self.progressLayers)
{
POPBasicAnimation *popEndAnimation = [POPBasicAnimation animation];
@amster
amster / YourViewController.m
Last active October 24, 2022 20:44
Load a UIWebView in iOS that can also load local resources like images, CSS, and JavaScript
// An example viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadWebView];
}
// The example loader
//
// Assumes you have an IBOutlet for the UIWebView defined: @property (strong, nonatomic) UIWebView *wv;
@steipete
steipete / FirstResponder.m
Created January 31, 2014 17:21
Getting the first responder... Unless you want to use the private [view firstResponder] this seems to be the only legal way. Or am I wrong?
UIView *PSPDFFindFirstResponderBeneathView(UIView *view) {
// Stop if e.g. we show an UIAlertView with a text field.
if (UIApplication.sharedApplication.keyWindow != view.window) return nil;
// Search recursively for first responder.
for (UIView *childView in view.subviews) {
if ([childView respondsToSelector:@selector(isFirstResponder)] && childView.isFirstResponder) return childView;
UIView *result = PSPDFFindFirstResponderBeneathView(childView);
if (result) return result;
}
@kevin-smets
kevin-smets / iterm2-solarized.md
Last active November 14, 2024 15:40
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k