Skip to content

Instantly share code, notes, and snippets.

View SunriseSunset.m
BOOL isCurrentlyDaytimeInNYC()
{
static CGFloat const latitudeNYC = 40.7831;
static CGFloat const longitudeNYC = 73.9712;
return isCurrentlyDaytime(latitudeNYC,
longitudeNYC);
}
View SunriseSunset.m
BOOL isCurrentlyDaytime(CGFloat latitude, CGFloat longitude)
{
// http://users.electromagnetic.net/bu/astro/iyf-calc.php
// http://aa.quae.nl/en/reken/zonpositie.html
static NSUInteger const secondsPerDay = 60*60*24;
static NSTimeInterval const julianLeap = 0.0009;
static double const degreeToRadian = M_PI/180.0;
static double const radianToDegree = 180.0/M_PI;
View ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var buttonA:UIButton!
@IBOutlet var buttonB:UIButton!
override func viewDidLoad() {
super.viewDidLoad()
View TraitViewController.swift
class TraitViewController: UIViewController {
//this function comes from the UITraitEnvironment protocol
override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
let horizontalSize = traitCollection.horizontalSizeClass
let verticalSize = traitCollection.verticalSizeClass
let previousHorizontalSize = previousTraitCollection.horizontalSizeClass
let previousVerticalSize = previousTraitCollection.verticalSizeClass
@BradB132
BradB132 / ViewController.swift
Created Jul 4, 2015
InterfaceBuilderTricks-2
View ViewController.swift
let testView = view.viewWithStringTag("testView")
println("TEST VIEW: \(testView)")
@BradB132
BradB132 / UIVIew+stringTag.swift
Created Jul 3, 2015
InterfaceBuilderTricks-1
View UIVIew+stringTag.swift
private var stringTagHandle: UInt8 = 0
extension UIView {
//use Objective C Associated Object API to add this property to UIView
@IBInspectable public var stringTag:String? {
get {
if let object = objc_getAssociatedObject(self, &stringTagHandle) as? String {
return object
}
@BradB132
BradB132 / TTBaseAnimator.h
Created Jun 10, 2015
ViewControllerTransitionsPart3-6
View TTBaseAnimator.h
@interface TTBaseAnimator : NSObject
@property (nonatomic) NSTimeInterval duration;
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning> )transitionContext;
@end
@BradB132
BradB132 / TTPushController.m
Last active Aug 29, 2015
ViewControllerTransitionsPart3-5
View TTPushController.m
@interface TTPushController ()
@property (nonatomic, strong) TTInteractivePinchTransition* transition;
@property (nonatomic, strong) UIPinchGestureRecognizer* pinch;
@end
// ...
- (void)viewDidLoad
@BradB132
BradB132 / TTInteractivePinchTransition.h
Created Jun 10, 2015
ViewControllerTransitionsPart3-4
View TTInteractivePinchTransition.h
@protocol TTInteractivePinchTransitionDelegate <NSObject>
-(void)delegateShouldPerformSegue:(TTInteractivePinchTransition*)transition
pinch:(UIPinchGestureRecognizer*)pinch;
@end
@interface TTInteractivePinchTransition : UIPercentDrivenInteractiveTransition
@property (nonatomic, weak) id<TTInteractivePinchTransitionDelegate> delegate;
-(void)handlePinch:(UIPinchGestureRecognizer*)pinch;
@BradB132
BradB132 / TTNavigationController.m
Last active Aug 29, 2015
ViewControllerTransitionsPart3-3
View TTNavigationController.m
- (id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController
{
if([_mostRecentController respondsToSelector:@selector(navigationController:interactionControllerForAnimationController:)])
{
return [(id<UINavigationControllerDelegate>)_mostRecentController navigationController:navigationController
interactionControllerForAnimationController:animationController];
}
return nil;
}