This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIView { | |
func currentFirstResponder() -> UIResponder? { | |
if self.isFirstResponder() { | |
return self | |
} | |
for view in self.subviews { | |
if let responder = view.currentFirstResponder() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
NewerOlder