Wrox Programmer Forums
|
BOOK: Beginning iPad Application Development
This is the forum to discuss the Wrox book Beginning iPad Application Development by Wei-Meng Lee; ISBN: 9780470641651
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iPad Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2010, 11:30 AM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default Chapter 12 Gestures

This chapter presented the information clearly, but I disliked how the implementations of the various gestures ignored changes made by other gestures. i.e. a "zoom" followed by a rotation would no longer be "zoomed", a rotation followed by a zoom wouldn't be rotated. The following changes allow you to make the changes cumulative.
Code:
@synthesize imageView;


CGAffineTransform currentState;
BOOL senderState = YES;

-(IBAction)handlePinchGesture:(UIGestureRecognizer *)sender
{
	if (senderState) {
		currentState = sender.view.transform;
		senderState = NO;
	}
	
	CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];

	sender.view.transform = CGAffineTransformScale(currentState, factor, factor);

	
	if(sender.state == UIGestureRecognizerStateEnded)
	{
		senderState = YES;
	}
}

-(IBAction)handleRotationGesture:(UIGestureRecognizer *)sender
{
	if (senderState) {
		currentState = sender.view.transform;
		senderState = NO;
	}
	CGFloat rotation = [(UIRotationGestureRecognizer *)sender rotation];
	
	sender.view.transform = CGAffineTransformRotate(currentState, rotation);
	
	if (sender.state == UIGestureRecognizerStateEnded) {
		senderState = YES;
	}
}

-(IBAction)handlePanGesture:(UIGestureRecognizer *)sender
{
	if (senderState) {
		currentState = sender.view.transform;
		senderState = NO;
	}
	CGPoint translation = [(UIPanGestureRecognizer *)sender translationInView:imageView];
	
	sender.view.transform = CGAffineTransformTranslate(currentState, translation.x, translation.y);
	
	if (sender.state == UIGestureRecognizerStateEnded) {
		senderState = YES;
	}
}
The variables
CGPoint netTranslation;
CGFloat lastScaleFactor=1;
CGFloat netRotation;
are no longer needed since you get the information about the current state from the view.

Last edited by thepianoguy; September 20th, 2010 at 12:38 PM.. Reason: Mistyped the Chapter number





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13 rock1233 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 October 6th, 2009 12:18 PM
Problems with Chapter 13 hooligan BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 November 11th, 2008 08:26 PM
Chapter 13 bwoll BOOK: Beginning Access 2003 VBA 1 June 7th, 2007 03:57 PM
Chapter 13 ElMorenito BOOK: Beginning ASP 3.0 0 January 14th, 2005 02:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.