250 CHAPTER 8: Putting It All Together^
gestures are also handled. However, they did leave out momentum swipes, the kind of
action that can keep a list scrolling for a while after you’ve lifted your finger.
Here we’ll need only the pinch and pan gestures. To your view controller’s
viewDidLoad() method, add Listing 8-2.
Listing 8-2. Allocating the gesture recognizers
UIPinchGestureRecognizer *pinchGesture =
[[UIPinchGestureRecognizer alloc]initWithTarget:self
action:@selector(handlePinchGesture:)];
[self.view addGestureRecognizer:pinchGesture];
UIPanGestureRecognizer *panGesture =
[[UIPanGestureRecognizer alloc]initWithTarget:self
action:@selector(handlePanGesture:)];
[self.view addGestureRecognizer:panGesture];
Next we need to add the two handlers, handlePanGesture() and handlePinchGesture(),
shown in Listing 8-3.
Listing 8-3. The Two Handlers for the Gesture Recognizers
- (IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender
{
static CGPoint prevLocation;
CGPoint translate = [sender translationInView:self.view];
UIGestureRecognizerState state;
state=sender.state;
if(state==UIGestureRecognizerStateBegan)
{
prevLocation=translate;
[m_SolarSystem lookAtTarget];
}
else if(state==UIGestureRecognizerStateChanged)
{
CGPoint currlocation =translate;
m_PointerLocation=CGPointMake(currlocation.x, currlocation.y);
[self setHoverPosition:0 location:currlocation prevLocation:prevLocation];
prevLocation=currlocation;
}
}