Search code examples
iphoneobjective-cuiviewuitouch

How can I resize the uiview like that of uiimageview on uiscrollview?


I need to give functionality to user of cropping the image. I am displaying the uiimageview on a view and on that another view is being shown which is movable like a small box.on moving the box, it will give me the coordinates and as per that I will create a new image from the uiimageview. In such a way I am giving the functionality of a cropping Image.

Till now I was giving a fixed height width of the box to crop,But now I need to give a functionality like on 2 fingers touch,my crop box gets resized as per my fingers' position like that of ScrollviewSuite example of apple. I am doing following :

 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{    
    UITouch *touch = [[event allTouches] anyObject];

    NSUInteger tapCount = [touch tapCount];
    UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
    [twoFingerTap setNumberOfTouchesRequired:2];
    [newView addGestureRecognizer:twoFingerTap];

    CGPoint touchLocation = [touch locationInView:self.view];

    oldX = touchLocation.x;
    oldY = touchLocation.y;
}


- (void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer 
{
    CGRect frame = newView.frame; \\newframe is the crop box
    frame.size.height += 100;
    newView.frame = frame;
}

But in this manner I am just able to increase the height in static manner. What should i do to fetch two finger touches and coordinates? Any help will be much appreciated. Thank you.


Solution

  • handleTwoFingerTap hide self.view and visible scroll view..means you have to take one uiview and one scrollview ..scrollview for Zooming