Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Draw This
($0.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-27-2008, 04:16 PM   #7 (permalink)
torynfarr
New Member
 
Join Date: May 2008
Posts: 38
torynfarr is an unknown quantity at this point
Default

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

Last edited by torynfarr; 07-27-2008 at 04:32 PM.
torynfarr is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,024
Threads: 93,868
Posts: 401,934
Top Poster: BrianSlick (7,964)
Welcome to our newest member, davincic
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.