开发者

Pinch gesture and single touch

I have a couple of questions,

1) I have开发者_运维技巧 a UIImageView control on a view. I would like to add the pinch gesture to allow zooming in and out.

2) I have the requirement to drop additional images on top of the base image, these images do not need to zoom, but they will need to remain in the original location that they were placed on the base image.

Now the question is this....

How do I test for a single touch and drag around, while also looking for a pinch and stretch gesture for the base image?

Thanks for everyone helps on this.

take care

tony


Add this in viewdidload:

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];

    [imageView addGestureRecognizer:pinchGesture];  //imageView is your base image 
    [pinchGesture release];




//Zooming of image
-(IBAction)handlePinchGesture:(UIPinchGestureRecognizer *) sender
{

    if (pictureTimer) {  //This is NSTimer. set pictureTimer=1 in viewdidLoad
        return;
    }


    CGFloat factor = [(UIPinchGestureRecognizer *) sender scale];
    if(factor >1)
    {
        sender.view.transform =CGAffineTransformMakeScale(lastScaleFactor +(factor-1), lastScaleFactor +(factor-1));
    }
    else {
        sender.view.transform=CGAffineTransformMakeScale(lastScaleFactor * factor, lastScaleFactor*factor);
    }

    if (sender.state==UIGestureRecognizerStateEnded) {
        if (factor>1) {
            lastScaleFactor +=(factor-1);
        }
        else {
            lastScaleFactor*= factor;
        }

    }

}

Your will get stretch to your base image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜