Retaining and reading variable information
Retaining and reading variable information
- Subject: Retaining and reading variable information
- From: FDW Development <email@hidden>
- Date: Thu, 15 Apr 2010 18:20:07 +0100
Hi guys im new to xcode and this is my first post
to the list. Im having some issues regarding storing data in variables.
Such a simple thing should cause me issues like this! haha!
Im trying to create a variable that stores a touches origin point and
the distance between touches, however my code seams to reset it to
0.000000 every time.
Any help on this would be much appreciated
My code is as follows...
viewControler.h
#import
<UIKit/UIKit.h>
@interface ModelViewController : UIViewController {
CGFloat *initialDistance;
}
@end
viewControler.m
-
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
switch ([allTouches count]) {
case 2: {
//Track the initial distance between two fingers.
UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
initialDistance = [self distanceBetweenTwoPoints:[touch1
locationInView:[self view]]
toPoint:[touch2
locationInView:[self view]]];
} break;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
switch ([allTouches count])
{
case 2: {
UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
//Calculate the distance between the two fingers.
CGFloat *finalDistance = [self
distanceBetweenTwoPoints:[touch1 locationInView:[self view]]
toPoint:[touch2 locationInView:[self view]]];
// Always ouputs initialDistance as 0.000000
NSLog(@"initialDistance: %f, finalDistance: %f",
initialDistance, finalDistance);
} break;
}
}
- (CGFloat)distanceBetweenTwoPoints:(CGPoint)fromPoint
toPoint:(CGPoint)toPoint {
float x = toPoint.x - fromPoint.x;
float y = toPoint.y - fromPoint.y;
return sqrt(x * x + y * y);
}
Regards
Stuart
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden