Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Created April 28, 2012 21:59
Show Gist options
  • Save jwoertink/2522357 to your computer and use it in GitHub Desktop.
Save jwoertink/2522357 to your computer and use it in GitHub Desktop.
//
// MyTestDriveViewController.m
// CoolApp
//
// Created by Jeremy Woertink on 4/28/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "MyTestDriveViewController.h"
@implementation MyTestDriveViewController
@synthesize touchItem = _touchItem;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupGestures];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark My cool code
-(void) setupGestures
{
UIPanGestureRecognizer *dragGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panPiece:)];
[dragGesture setMaximumNumberOfTouches:2];
[dragGesture setDelegate:self];
[self.touchItem addGestureRecognizer:dragGesture];
}
-(void) panPiece:(UIPanGestureRecognizer *)gestureRecognizer
{
UIView *piece = [gestureRecognizer view];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
CGPoint translation = [gestureRecognizer translationInView:[piece superview]];
NSLog(@"\n\n Piece: %@\n\n", piece);
[piece setCenter:CGPointMake([piece center].x + translation.x, [piece center].y + translation.y)];
[gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment