Learn 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 cl...
https://www.czetsuyatech.com/2010/12/xcode-stanford-stalker-project.html
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?
Steps:
1.) Create a new WIndow-based Application project, Stalker
2.) Create a new class TouchResponder
TouchResponder.h
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
Steps:
1.) Create a new WIndow-based Application project, Stalker
2.) Create a new class TouchResponder
TouchResponder.h
#import <UIKit/UIKit.h> @interface TouchResponder : UIView { IBOutlet UIView *stalker; } @endTouchResponder.m
#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 { } @end2.) 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
Post a Comment