Skip to content

Instantly share code, notes, and snippets.

@SquaredTiki
Created April 20, 2010 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SquaredTiki/372120 to your computer and use it in GitHub Desktop.
Save SquaredTiki/372120 to your computer and use it in GitHub Desktop.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchDown");
UITouch *touch = [touches anyObject];
UIView *aView = [self.view viewWithTag:1];
firstTouch = [touch locationInView:self.view];
if (CGRectContainsPoint(aView.frame, firstTouch)) {
butContains = YES;
NSLog(@"butContains = %d", butContains);
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *array = [touches allObjects];
UITouch *specificTouch = [array objectAtIndex:0];
currentTouch = [specificTouch locationInView:self.view];
UIView *aView = [self.view viewWithTag:1];
if (butContains == YES) {
NSLog(@"touch in subView/contentView");
aView.frame = CGRectMake(currentTouch.x, currentTouch.y , 130.0, 21.0);
}
NSLog(@"touch moved");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
currentTouch = [touch locationInView:self.view];
UIView *aView = [self.view viewWithTag:1];
if (butContains == YES) {
NSLog(@"touch in subView/contentView");
aView.frame = CGRectMake(currentTouch.x, currentTouch.y, 130.0, 21.0);
}
butContains = NO;
NSLog(@"touch ended");
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft];
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
- (IBAction)add:(id)sender{
UIView *aView = [[UIView alloc] initWithFrame:
[[UIScreen mainScreen] applicationFrame]];
aView.frame = CGRectMake(0, 0, 130, 21);
aView.tag = 1;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"You Added Me!" forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, 130, 21);
button.enabled = NO;
[aView addSubview:button];
[self.view insertSubview:aView atIndex:0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment