Skip to content

Instantly share code, notes, and snippets.

//
// UIScrollView+zoomToCenterWithScale.h
// locationme
//
// Created by 金燕赖 on 14-6-22.
// Copyright (c) 2014年 ljy. All rights reserved.
//
#import <UIKit/UIKit.h>
//CGDisplayIOServicePort is depreciated in OS 10.9 – so you have to use IOServiceGetMatchingServices to get the service parameter for IODisplaySetFloatParameter.
- (void) setBrightnessTo: (float) level
{
io_iterator_t iterator;
kern_return_t result = IOServiceGetMatchingServices(kIOMasterPortDefault,
IOServiceMatching("IODisplayConnect"),
&iterator);
@edwardean
edwardean / distanceToLocationfromLocation.m
Created August 24, 2016 06:16 — forked from quellish/distanceToLocationfromLocation.m
NSExpression distanceToLocation:fromLocation:
expression = [NSExpression expressionForFunction:@"distanceToLocation:fromLocation:"
arguments:@[
[NSExpression expressionForConstantValue:to ],
[NSExpression expressionForConstantValue:from ]
]
];
result = (NSNumber *)[expression expressionValueWithObject:nil context:nil];
@edwardean
edwardean / predicatedistanceToLocationfromLocation.m
Created August 24, 2016 06:16 — forked from quellish/predicatedistanceToLocationfromLocation.m
NSPredicate distanceToLocation:fromLocation
predicate = [NSPredicate predicateWithFormat:@"distanceToLocation:fromLocation:(%@, %@) =< %@",
toLocation,
fromLocation,
expectedDistance
];
@edwardean
edwardean / UIView+PSPDFKitAdditions.m
Created August 18, 2016 07:57 — forked from steipete/UIView+PSPDFKitAdditions.m
Get the closes view controller to the current view.
@implementation UIView (PSPDFKitAdditions)
- (UIViewController *)pspdf_closestViewController {
UIResponder *responder = self;
while ((responder = [responder nextResponder])) {
if ([responder isKindOfClass:UIViewController.class]) break;
}
return (UIViewController *)responder;
}
@edwardean
edwardean / PSPDFBlockAssert.m
Created August 18, 2016 07:47 — forked from steipete/PSPDFBlockAssert.m
Check if object is a block - nice for assertions.
PSPDF_EXTERN BOOL PSPDFIsBlock(id _Nullable block) {
static Class blockClass;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
blockClass = [^{} class];
while ([blockClass superclass] != NSObject.class) {
blockClass = [blockClass superclass];
}
});
@edwardean
edwardean / gist:6b05bf8b15a4f161798c6c21eaea592a
Created August 18, 2016 07:43 — forked from steipete/ios-xcode-device-support.sh
Using Xcode 7.3.1 and iOS 10 devices
// The trick is to copy the DeviceSupport folder from the beta to the stable version.
cp -r /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/10.0\ \(14A5261u\) /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/
// Then restart Xcode. You might need to do that for every beta of iOS 10/Xcode 8.
@edwardean
edwardean / UIColor+isLight.h
Created June 16, 2016 03:41 — forked from kaishin/UIColor+isLight.h
Get whether a color is dark or light using either luminance or lightness.
#import <UIKit/UIKit.h>
@interface UIColor (isLight)
- (CGFloat)lightness;
- (CGFloat)perceivedLightness;
- (CGFloat)perceivedLightnessW3C;
- (BOOL)isLight;
- (BOOL)isPerceivedLightW3C;
- (BOOL)isPerceivedLight;
@edwardean
edwardean / iOS7PresentSemiTransVC.m
Created June 7, 2016 06:49 — forked from fragno/iOS7PresentSemiTransVC.m
iOS7以上present半透明的vc
- (void)presentOverViewController:(ASViewController *)viewController
{
if ([[UIDevice currentDevice].systemVersion integerValue] >= 8) {
//For iOS 8
viewController.providesPresentationContextTransitionStyle = YES;
viewController.definesPresentationContext = YES;
viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[viewController presentViewController:self animated:NO completion:nil];
}
else
@edwardean
edwardean / iOS8ViewController.m
Created June 7, 2016 04:11 — forked from se-rg-os/iOS8ViewController.m
iOS 8 fix to support old methods of device orientation changes
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
//The device has already rotated, that's why this method is being called.
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
//fixes orientation mismatch (between UIDeviceOrientation and UIInterfaceOrientation)
UIInterfaceOrientation toOrientation;
switch (deviceOrientation) {
case UIDeviceOrientationUnknown:
toOrientation = UIInterfaceOrientationUnknown;