iPhone touch event programming stanford's stalker project

Moving on with Stanford's set of exercise, here I am working on how to handle iPhone's touch events. I will replicate the Stalker class created by Paul?

1.) Create a new WIndow-based Application project, Stalker

2.) Create a new class TouchResponder
#import <UIKit/UIKit.h>
@interface TouchResponder : UIView {
 IBOutlet UIView *stalker;
#import "TouchResponder.h"
@implementation TouchResponder
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
 [UIView beginAnimations:@"stalk" context:nil];
 [UIView setAnimationDuration:1];
 [UIView setAnimationBeginsFromCurrentState:YES];
 UITouch *touch = [touches anyObject];
 stalker.center = [touch locationInView:self];
 [UIView commitAnimations];
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
2.) Open the interface builder, locate the UIView from the library and drag and drop to the window
  a.) Open the view's Identity Inspector and change the class to: TouchResponder

3.) Repeat step 2, while the second view is selected make the following changes:
  a.) In the Attributes Inspector, set the Background color to red
  b.) In the Size Inspector, x=0, y=0, w=20, h=20

4.) Finally, we will link the first view to the stalker outlet by clicking on the large view and move the cursor to the small view.
5.) stalker outlet should show
iPhone touch event programming stanford's stalker project iPhone touch event programming stanford's stalker project Reviewed by Edward Legaspi on Thursday, December 23, 2010 Rating: 5

No comments:

Powered by Blogger.