PDA

View Full Version : Pinching and zooming in




gryym
Aug 3, 2008, 08:31 PM
Hey guys, do you know what documentation or website that i could refer to if i want to do some pinching? I was thinking like pinching on a tile and then it zooms in much like when you hold "Control + double finger scroll" on the Macs. And yeah, it can zoom out too to its original position.

Thanks.



gryym
Aug 4, 2008, 08:26 PM
So here i planned out a pseudo code as a foundation to what i am gonna do in regards to the pinching.

(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
Place finger on phone
Detect if touches on phone == 2
- If (touch<2)
Nothing happen.
else if (touch == 2)
Detect whether its moving away from each other.
if (moving away)
call a "CGAffineTransformScale" (correct me if i'm
wrong) onto the image to zoom in.
else
zoom out of the image until the image gets scaled back
to its original position

It's a rough idea of what's going through my head, but i think i'm getting it somehow right. If anyone can shed some light onto this matter, its greatly appreciated.

Thanks in advance. :)

Taum
Aug 5, 2008, 04:57 AM
Hi,

If you're looking for Maps-like or Photos-like behavior, check out UIScrollView : it will do all the zooming/panning work for you.

If you need a more custom behavior though, I think you're on the right tracks. You want to keep track of the UITouch and check the euclidean distance between two touches to see if it grows up or down. Then you'll update the layer's transform property accordingly (scale.x & scale.y probably). You can read more info about layers/transforms in the Core Animation Programming Guide

gryym
Aug 5, 2008, 08:17 PM
Thanks for the reply.

It looks like what i am trying to accomplish is similar to the photos-like behaviour. I'm currently checking out UIScrollView now and i think it works somewhere on a level which I expected it to. Now, the image looks itself to be scaled or enlarged.

Now, i'm trying to set the UIScrollView to "attach" itself to the view instead of the image. Will get back if its a success =)

gryym
Aug 6, 2008, 12:16 AM
Managed to have the view scaled entirely instead of the image being enlarged. Found out that the cause was in the function:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.view;
}

Initially, it was returning the image that i had placed instead. So now it works. However, a few problems or modifications i want to make and i do not know yet how to:

**(1)Zoom into point of pinching instead of a default spot that its zooming into, which now is the top left corner of the scrollview.**

(2)Move the view around until the boundaries when the scrollview's scaled.

**(3)When the orientation is changed to landscape, the scrollview is not updated to that landscape view and still thinks it is in portrait mode.**

Thanks for the help :)

Note: (1) and (3) is "solved". Poses no orientation problems now. A guy just gave me a statement that the pinching in the IPhone simulator will not work according to your boundary according for the pinching. So that may be the reason that it's always like zooming to a corner of the screen size.Not sure about this, though...
(2) still eludes my understanding...