Dipen Chudasama February 2016

How to prevent button resize when zoom super view?

I was adding multiple gestures in one view, The view have a one close button at corner of the view, Everything is working fine but when I am zoom that view close button was also zoom with that view, Now I want to zoom only that view not that close button, Please suggest me How to do this ?

see below image for reference.

enter image description here

Code for pinch Zoom

   -(void)addStickersWithView:(UIView*)view image:(UIImage*)image{

    CGPoint center = self.imgPhoto.center;
    UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
    UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotatePiece:)];
    [imgView setContentMode:UIViewContentModeScaleToFill];
    UIView *viewZoom = [[UIView alloc] initWithFrame:CGRectMake(center.x-45,center.y-45, 90, 90)];
   // [viewZoom setBackgroundColor:[UIColor redColor]];
    imgView.frame = CGRectMake(5, 5, CGRectGetWidth(viewZoom.frame)-10, CGRectGetHeight(viewZoom.frame)-10);
    [viewZoom addSubview:imgView];
    [viewZoom addGestureRecognizer:rotationGesture];

    UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePiece:)];
    [pinchGesture setDelegate:self];
    [viewZoom addGestureRecognizer:pinchGesture];

    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveImage:)];
    [panGesture setMinimumNumberOfTouches:1];
    [panGesture setMaximumNumberOfTouches:1];
    [viewZoom addGestureRecognizer:panGesture];

    UIButton *btnCloseSticker = [UIButton buttonWithType:UIButtonTypeCustom];

    [btnCloseSticker setBounds:CGRectMake(0, 0, 30,30)];
    [btnCloseSticker setImage:[UIImage imageNamed:@"close1.png"] forState:UIControlStateNormal];
    [btnCloseStick        

Answers


Eli Braginskiy February 2016

The easy way to do it is to remove the close button from that view, and add it on top of the view you're zooming with a different view.

You can use. insertSubview:aboveSubview:


Crazy Developer February 2016

In place of scaling view. it's batter to calculate the frame with your zoom level. and update the frame of the view. check out the below method.

- (IBAction)scalePiece:(UIPinchGestureRecognizer *)gestureRecognizer {
    if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
        // Reset the last scale, necessary if there are multiple objects with different scales
        lastScale = [gestureRecognizer scale];
    }

    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||
        [gestureRecognizer state] == UIGestureRecognizerStateChanged) {

        CGFloat newScale = 1 -  (lastScale - [gestureRecognizer scale]);
        [self changeScale:newScale];

        lastScale = [gestureRecognizer scale];  // Store the previous scale factor for the next pinch gesture call
    }
}

-(void)changeScale :(float)newScale{

    CGAffineTransform transform = CGAffineTransformScale([viewForpinch transform], newScale, newScale);
    viewForpinch.transform = transform;

    float scale = viewForpinch.transform.a;
    float buttonScale = 1 / scale;

    btnl.transform= CGAffineTransformScale(CGAffineTransformIdentity, buttonScale, buttonScale);


}

Post Status

Asked in February 2016
Viewed 2,799 times
Voted 7
Answered 2 times

Search




Leave an answer