Created
April 20, 2010 06:20
-
-
Save SquaredTiki/372120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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