Skip to content

Instantly share code, notes, and snippets.

@hjon
hjon / Auto-layout-keyboard-adjustment.md
Created October 31, 2016 16:03 — forked from dlo/Auto-layout-keyboard-adjustment.md
How to adjust a view's height with Auto Layout when a keyboard appears or disappears in iOS 7.

This gist outlines how to resize a view when a keyboard appears using Auto Layout (there are a bunch of code samples out there that manually adjust the view's frame, but that's just so 2013). The method I outline below works universally on both iPhone and iPad, portrait and landscape, and is pretty darn simple.

Setting Up

The first thing to do is to define our containing view controller, the view, and the bottom constraint that we'll use to adjust its size.

Here's HeightAdjustingViewController.h. We don't need to expose any public properties, so it's pretty bare.

@hjon
hjon / NSURLWithParameters.m
Created February 23, 2012 22:47 — forked from 0xced/NSURLWithParameters.m
How to (ab)use TWRequest to create a NSURL with parameters easily
{
NSURL *baseURL = [NSURL URLWithString:@"http://duckduckgo.com/"];
NSDictionary *parameters = [NSDictionary dictionaryWithObject:@"TWRequest -site:apple.com" forKey:@"q"];
// With TWRequest: 1 line with **correct percent escaping**
NSURL *urlA = [[[[TWRequest alloc] initWithURL:baseURL parameters:parameters requestMethod:TWRequestMethodGET] signedURLRequest] URL];
// Without TWRequest: 10 lines with wrong percent escaping (http://www.openradar.me/6546984)
NSMutableString *query = [NSMutableString string];
for (NSString *key in parameters)
@hjon
hjon / keep_current_file_open.sh
Created February 10, 2012 03:01 — forked from wearhere/keep_current_file_open.sh
Keep your current source file open in Xcode after a run completes (a.k.a don't die in main.m)
#! /bin/sh
# On alternate invocations, this script
# saves the path of the source file currently open in Xcode
# and restores the file at that path in Xcode.
#
# By setting Xcode (in Behaviors) to run this script when "Run Starts"
# and when "Run Completes", you can prevent it from switching to main.m
# when a run finishes.
# See http://stackoverflow.com/questions/7682277/xcode-4-2-jumps-to-main-m-every-time-after-stopping-simulator
@hjon
hjon / iOSDocumentMigrator.m
Created December 6, 2011 18:12 — forked from steipete/iOSDocumentMigrator.m
Helps migrating documents between iOS <= 5.0 and >= 5.0.1 to comply with Apple's iCloud guidelines. Follow @steipete on Twitter for updates.
#include <sys/xattr.h>
/// Set a flag that the files shouldn't be backuped to iCloud.
+ (void)addSkipBackupAttributeToFile:(NSString *)filePath {
u_int8_t b = 1;
setxattr([filePath fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
}
/// Returns the legacy storage path, used when the com.apple.MobileBackup file attribute is not available.
+ (NSString *)legacyStoragePath {
//
// MNDocumentController.h
// MindNodeTouch
//
// Created by Markus Müller on 22.12.08.
// Copyright 2008 Markus Müller. All rights reserved.
//
#import <Foundation/Foundation.h>
@class MNDocumentReference;
@hjon
hjon / gist:1191556
Created September 3, 2011 18:12 — forked from steipete/gist:1175357
Easy [fade] animation for UIImageView.image
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
selected_ = selected;
if (animated) {
CATransition *transition = [CATransition animation];
transition.duration = 0.25f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.selectionImageView.layer addAnimation:transition forKey:nil];
}
@hjon
hjon / UIImage+PSPDFKitAdditions.m
Created August 13, 2011 20:59 — forked from steipete/UIImage+PSPDFKitAdditions.m
Preload UIImage for super-smooth interaction. especially great if you use JPGs, which otherwise produce a noticeable lag on the main thread.
- (UIImage *)pspdf_preloadedImage {
CGImageRef image = self.CGImage;
// make a bitmap context of a suitable size to draw to, forcing decode
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef imageContext = CGBitmapContextCreate(NULL, width, height, 8, width*4, colourSpace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
#!/usr/bin/python
# Nicolas Seriot
# 2011-01-06
# https://gist.github.com/768457
"""
Input: path of an Objective-C project
Output: import dependancies Graphviz format
#!/usr/bin/python
# Nicolas Seriot
# 2011-01-06
# http://github.com/nst/objc_dep
"""
Input: path of an Objective-C project
Output: import dependancies Graphviz format