Sure : )
ViewController.h
Code:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
UILabel *touchStatusLabel;
NSTimer *touchTimer;
}
@property (nonatomic, retain) UILabel *touchStatusLabel;
@property (nonatomic, retain) NSTimer *touchTimer;
@end
ViewController.m
Code:
#import "ViewController.h"
@interface ViewController (PrivateMethods)
- (void)startTouchTimer:(float)delay;
- (void)touchHeld:(NSTimer*)timer;
@end
@implementation ViewController
@synthesize touchTimer, touchStatusLabel;
- (void)loadView {
UIView *containerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
containerView.backgroundColor = [UIColor redColor];
containerView.clearsContextBeforeDrawing = YES;
self.view = containerView;
[containerView release];
}
- (void)viewDidLoad {
// Rotates the view into landscape mode, with the home button on the right.
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
self.view.transform = transform;
// Repositions and resizes the view.
CGRect contentRect = CGRectMake(-80, 80, 480, 320);
self.view.bounds = contentRect;
// Setup a UILabel in the top left corner.
CGRect labelFrame = CGRectMake(-80, 105, 100, 25);
touchStatusLabel = [[UILabel alloc] initWithFrame:labelFrame];
touchStatusLabel.font = [UIFont systemFontOfSize:16];
touchStatusLabel.textColor = [UIColor whiteColor];
touchStatusLabel.textAlignment = UITextAlignmentLeft;
touchStatusLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
[self.view addSubview: touchStatusLabel];
}
- (void)startTouchTimer:(float)delay {
touchTimer = [NSTimer scheduledTimerWithTimeInterval:delay target:self selector:@selector(touchHeld:) userInfo:nil repeats:NO];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
touchStatusLabel.text = @"Touch Start";
[self startTouchTimer:3.00];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
touchStatusLabel.text = @"Touch Moved";
if ([touchTimer isValid]) [touchTimer invalidate];
[self startTouchTimer:3.00];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
touchStatusLabel.text = @"Touch Ended";
if ([touchTimer isValid]) [touchTimer invalidate];
}
- (void)touchHeld:(NSTimer*)timer {
touchStatusLabel.text = @"Touch Held";
if ([touchTimer isValid]) [touchTimer invalidate];
[self startTouchTimer:3.00];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
- (void)dealloc {
[touchStatusLabel release];
[touchTimer release];
[super dealloc];
}
@end
This *should* create a big red UIView rotated landscape style with a UILabel in the top right. As the touch state changes, the UILabel should be updated.... with the added bonus of a custom made touch event "touchHeld" which is a touch state that will occur if you hold your finger on the screen for 3 seconds.
Note: I didn't test to see if this compiles... I just took out the stuff from my app that is related specifically to my app... and copy and pasted the rest in here.
Hope this helps clear it up!
-Toryn