Skip to content

Instantly share code, notes, and snippets.

Avatar

Oliver Drobnik odrobnik

View GitHub Profile
@odrobnik
odrobnik / gist:2711594
Created May 16, 2012
Force decompression of UIImage on background queue before setting on UIImageView
View gist:2711594
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
A physical jump/bounce animation as CAKeyframeAnimation
View gist:2769082
+ (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 Jun 4, 2012
Please comment: adding tap and long press action with blocks to any view
View gist:2865589
#import <objc/runtime.h>
@implementation UIView (DTActionHandlers)
- (id)tapActionBlock
{
return objc_getAssociatedObject(self, "DTActionHandlerTap");
}
- (void)addTapActionWithBlock:(void (^)(void))block
@odrobnik
odrobnik / gist:2867970
Created Jun 4, 2012
Riddle: why is the parameter UIView in one place and UITapGestureRecognizer in another?
View gist:2867970
#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 Jun 5, 2012
Inner Shadow on Label
View gist:2872435
- (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 Jun 6, 2012
WWDC 2012 Apps in Banner
View gist:2881890
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 Jul 13, 2012
Weird GeoCorder Crash
View gist:3104795
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 Jul 13, 2012
Code where the crash occurred
View gist:3104860
- (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 Aug 31, 2012
CoreImage: EAGLContext framebuffer or renderbuffer incorrectly configured!
View gist:3554385
- (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 Aug 31, 2012
Is this correct?
View gist:3554821
- (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