Skip to content

Instantly share code, notes, and snippets.

View odrobnik's full-sized avatar

Oliver Drobnik odrobnik

View GitHub Profile
@odrobnik
odrobnik / gist:2711594
Created May 16, 2012 15:58
Force decompression of UIImage on background queue before setting on UIImageView
dispatch_queue_t queue = dispatch_queue_create("PlusFlickrPhotoView Queue", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{
// force decompress of image
UIGraphicsBeginImageContext(CGSizeMake(1, 1));
[image drawAtPoint:CGPointZero];
UIGraphicsEndImageContext();
// set the image on main thread
dispatch_sync(dispatch_get_main_queue(), ^{
@odrobnik
odrobnik / gist:2769082
Created May 22, 2012 13:32
A physical jump/bounce animation as CAKeyframeAnimation
+ (CAKeyframeAnimation *)jumpAnimation
{
// these three values are subject to experimentation
CGFloat initialMomentum = 150.0f; // positive is upwards, per sec
CGFloat gravityConstant = 250.0f; // downwards pull per sec
CGFloat dampeningFactorPerBounce = 0.6; // percent of rebound
// internal values for the calculation
CGFloat momentum = initialMomentum; // momentum starts with initial value
CGFloat positionOffset = 0; // we begin at the original position
@odrobnik
odrobnik / gist:2865589
Created June 4, 2012 00:21
Please comment: adding tap and long press action with blocks to any view
#import <objc/runtime.h>
@implementation UIView (DTActionHandlers)
- (id)tapActionBlock
{
return objc_getAssociatedObject(self, "DTActionHandlerTap");
}
- (void)addTapActionWithBlock:(void (^)(void))block
@odrobnik
odrobnik / gist:2867970
Created June 4, 2012 12:11
Riddle: why is the parameter UIView in one place and UITapGestureRecognizer in another?
#import "UIView+DTActionHandlers.h"
#import <objc/runtime.h>
char * const kDTActionHandlerTapBlockKey = "DTActionHandlerTapBlockKey";
char * const kDTActionHandlerTapGestureKey = "DTActionHandlerTapGestureKey";
char * const kDTActionHandlerLongPressBlockKey = "DTActionHandlerLongPressBlockKey";
char * const kDTActionHandlerLongPressGestureKey = "DTActionHandlerLongPressGestureKey";
@implementation UIView (DTActionHandlers)
@odrobnik
odrobnik / gist:2872435
Created June 5, 2012 03:25
Inner Shadow on Label
- (void)drawTextInRect:(CGRect)rect
{
[super drawTextInRect:rect];
CGContextRef ctx = UIGraphicsGetCurrentContext();
NSString *fontName = self.font.fontName;
CGFloat fontSize = self.font.pointSize;
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)fontName, fontSize, NULL);
@odrobnik
odrobnik / gist:2881890
Created June 6, 2012 13:34
WWDC 2012 Apps in Banner
Please help complete and sort this list. These are the icons visible in the WWDC 2012 Banner. Roughly sorted by size.
http://www.cocoanetics.com/files/WWDC2012_Banner.png
alternate, high res pictures of the Banner:
http://cdn.macrumors.com/article-new/2012/06/photo.jpg
Path - http://itunes.apple.com/us/app/path/id403639508?mt=8
Star Walk - http://itunes.apple.com/app/star-walk-guide-dastronomie/id295430577?mt=8
Instagram - http://itunes.apple.com/us/app/instagram/id389801252?mt=8
@odrobnik
odrobnik / gist:3104795
Created July 13, 2012 13:05
Weird GeoCorder Crash
Process: GeoCorder [45519]
Path: /Users/USER/Library/Application Support/iPhone Simulator/*/GeoCorder.app/GeoCorder
Identifier: GeoCorder
Version: ??? (???)
Code Type: X86 (Native)
Parent Process: launchd [131]
Date/Time: 2012-07-10 21:32:53.939 +0300
OS Version: Mac OS X 10.7.4 (11E53)
Report Version: 9
@odrobnik
odrobnik / gist:3104860
Created July 13, 2012 13:21
Code where the crash occurred
- (void)recordLocation:(CLLocation *)location
{
if (previousRecordedLocation)
{
NSTimeInterval interval = [location.timestamp timeIntervalSinceDate:previousRecordedLocation.timestamp];
NSTimeInterval distance = [location distanceFromLocation:previousRecordedLocation];
CLLocationDistance currentSpeed = distance/interval;
if (previousRecordedSpeed)
@odrobnik
odrobnik / gist:3554385
Created August 31, 2012 15:15
CoreImage: EAGLContext framebuffer or renderbuffer incorrectly configured!
- (void)drawCIImage:(CIImage *)image
{
CGRect rect = [image extent];
// http://stackoverflow.com/questions/8778117/video-filtering-in-iphone-is-slow
GLuint _renderBuffer;
CGContextRef cgContext;
CIContext *coreImageContext;
@odrobnik
odrobnik / gist:3554821
Created August 31, 2012 15:42
Is this correct?
- (void)drawCIImage:(CIImage *)image
{
CGRect rect = [image extent];
CIContext *coreImageContext;
EAGLContext *glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:glContext];
// http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/WorkingwithEAGLContexts/WorkingwithEAGLContexts.html