• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calculating Scale Factor touchesMoved event.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calculating Scale Factor touchesMoved event.


  • Subject: Re: Calculating Scale Factor touchesMoved event.
  • From: Gustavo Adolfo Pizano <email@hidden>
  • Date: Thu, 2 Dec 2010 17:42:20 +0100

Ok I got something similar to what I want..

@ glenn I see the "180 rotation when first move" still happens any idea?


her eis the code now

		CGPoint Location = [[touches anyObject] locationInView:self];
		CGPoint p =	[self convertPoint:self.center fromView:self.superview];
		int x = p.x;
		int y = p.y;

		float dx = Location.x - x;
		float dy = Location.y - y;
		//CGPoint p1 = [aTouch locationInView:self];
		//CGPoint distance	= CGPointDelta(firstTouchPoint,[aTouch
locationInView:self]);
		//atan2(p1.y - firstTouchPoint.y, p1.x - firstTouchPoint.x)
		double a = atan2(-dx,dy);
		//CGFloat a = atan2(p1.y - firstTouchPoint.y, p1.x - firstTouchPoint.x);

		rotating = YES;


		//Now im gonna chekc if I  should enlarge
		CGFloat newDistFromCenter = [self getCurrentDistanceFromCenter:aTouch];
		CGFloat deltaCenter = newDistFromCenter - dist;

		// Get distance between points
		CGFloat currentDistance = distanceBetweenPoints(firstTouchPoint,Location);
		CGFloat previousDistance =
distanceBetweenPoints(firstTouchPoint,[aTouch
previousLocationInView:self]);

		// Figure new scale

		CGFloat distanceRatio =  currentDistance/previousDistance;

		if(0.5 <= distanceRatio && distanceRatio <= 1.3){
			NSLog(@"current %f, Previous %f, Ratio %f", currentDistance,
previousDistance, distanceRatio);
			bc_selectedItem.transform =
CGAffineTransformScale(bc_selectedItem.transform,distanceRatio,
distanceRatio);
			CGRect b = self.bounds;
			b.size.width += deltaCenter;
			b.size.height += deltaCenter;
			self.bounds = b;
			dist = newDistFromCenter;

		}
		self.transform= CGAffineTransformRotate(self.transform, a);
		bc_selectedItem.transform =
CGAffineTransformRotate(bc_selectedItem.transform, a);
		actualAngle = a;

		firstTouchPoint = p;
		[self setNeedsDisplay];

Thanks in Advance

Gustavo




On Thu, Dec 2, 2010 at 5:08 PM, Gustavo Adolfo Pizano
<email@hidden> wrote:
> glenn thanks... thats solves one preoblem I had no  idea why was that..
>
> Now im trying for the second problem the following:
>
> CGFloat currentDistance = distanceBetweenPoints(firstTouchPoint,p);
>                CGFloat previousDistance = distanceBetweenPoints(p,[aTouch
> previousLocationInView:self]);
>
>                // Figure new scale
>
>                CGFloat distanceRatio = currentDistance / previousDistance;
>                NSLog(@"current %f, Previous %f, Ratio %f", currentDistance,
> previousDistance, distanceRatio);
>
>
> where firstTouchPoint is where touchesBegan point started, and p is
> the current point in the touchesmoved,
>
> Its working but scaling down when it should scale up and vice versa.
>
> G.
>
> On Thu, Dec 2, 2010 at 4:41 PM, glenn andreas <email@hidden> wrote:
>>
>> On Dec 2, 2010, at 9:37 AM, Gustavo Adolfo Pizano wrote:
>>> now in my touches moved I do the following, the first part applies a
>>> rotation, which is working properly, except that after the first move
>>> the angle is 180 from what the view has, so you see that the view
>>> turns 180 degrees!!,
>>
>>>               CGFloat a = atan2(-dx,dy);
>>
>>
>>
>> atan2's parameters are declared as:
>>
>>     double  atan2(double y, double x);
>>
>>
>>
>>
>> Glenn Andreas                      email@hidden
>> The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL
>>
>>
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Calculating Scale Factor touchesMoved event. (From: Gustavo Adolfo Pizano <email@hidden>)
 >Re: Calculating Scale Factor touchesMoved event. (From: glenn andreas <email@hidden>)
 >Re: Calculating Scale Factor touchesMoved event. (From: Gustavo Adolfo Pizano <email@hidden>)

  • Prev by Date: rotate UIImage based on rotation of UIView
  • Next by Date: Basic HTTP program failed to compile
  • Previous by thread: Re: Calculating Scale Factor touchesMoved event.
  • Next by thread: rotate UIImage based on rotation of UIView
  • Index(es):
    • Date
    • Thread