Skip to content

Instantly share code, notes, and snippets.

View danmartyn's full-sized avatar

Daniel Martyn danmartyn

  • Ceridian
  • Canada
View GitHub Profile
// Create a UITapGestureRecognizer and add it to the view
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tap];
// In the handleTap Method add
- (void)handleTap:(UITapGestureRecognizer *)tap
{
[self.view endEditing:YES];
}
@danmartyn
danmartyn / longPress
Created May 28, 2013 04:23
Handle Long Press
- (void)handleLongPress:(UILongPressGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"UIGestureRecognizerStateEnded");
//Do Whatever You want on End of Gesture
}
else if (sender.state == UIGestureRecognizerStateBegan){
NSLog(@"UIGestureRecognizerStateBegan.");
//Do Whatever You want on Began of Gesture
}
}
@danmartyn
danmartyn / lastPhoto
Created June 15, 2013 08:19
Get the Last Photo
// Link Against Assets Library
// #import <AssetsLibrary/AssetsLibrary.h>
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
// Within the group enumeration block, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
@danmartyn
danmartyn / showCamera
Created June 15, 2013 08:20
Show Camera
// setup a picker for the camera
UIImagePickerController *cameraController = [[UIImagePickerController alloc] init];
cameraController.delegate = self;
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraController.allowsEditing = YES;
[self presentViewController:cameraController animated:YES completion:nil];
@danmartyn
danmartyn / imageLibrary
Created June 15, 2013 08:20
Image Library
UIImagePickerController *libraryController = [[UIImagePickerController alloc] init];
libraryController.delegate = self;
libraryController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
libraryController.allowsEditing = YES;
// if on the ipad, show the library in a popover
if (iPad)
{
UIPopoverController *libraryPopover = [[UIPopoverController alloc] initWithContentViewController:libraryController];
[libraryPopover presentPopoverFromRect:self.rectToPresentPopoverFrom inView:self.scrollView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
@danmartyn
danmartyn / imagePickerControllerDelegate
Created June 15, 2013 08:22
UIImagePickerController Delegate Methods
#pragma mark -
#pragma mark UIImagePickerController Delegate Methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// dismiss the picker
if (self.popover)
{
[self.popover dismissPopoverAnimated:YES];
self.popover = nil;
@danmartyn
danmartyn / Singleton
Created July 16, 2013 05:09
Singleton for Obj-C
+ (<#Class#> *)sharedManager
{
static <#Class#> *sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManager = [[<#Class#> alloc] init];
// other initialisation stuff
});
return sharedManager;
}
@danmartyn
danmartyn / restartMacApp
Created July 22, 2013 05:24
This is a cocoa method for restarting a mac app
+(void)restart:(id)sender
{
NSString *restartScript = @"while ps -p $1 > /dev/null; do sleep 0.1; done; open \"$2\"";
NSArray *arguments = [NSArray arrayWithObjects:
@"-c", restartScript,
@"",
[NSString stringWithFormat:@"%d",[[NSProcessInfo processInfo] processIdentifier]],
[[NSBundle mainBundle] bundlePath],
nil];
[NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:arguments];
@danmartyn
danmartyn / Version String
Created July 29, 2013 04:15
Returns the app name, version and build number
- (NSString *)appNameAndVersionNumberDisplayString {
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *appDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
NSString *majorVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSString *minorVersion = [infoDictionary objectForKey:@"CFBundleVersion"];
return [NSString stringWithFormat:@"%@, Version %@ (%@)",
appDisplayName, majorVersion, minorVersion];
}
@danmartyn
danmartyn / target
Created September 2, 2013 05:31
Add target for cocoa app
1) Choose the target you want to add to
2) Choose Build Settings
3) Search for 'macros'
4) Add a macro
To use the macro in the app:
#ifdef MACRO
// do some stuff
#elif OTHERMACRO
// do other stuff