Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:42:30+00:00 2026-06-06T05:42:30+00:00

I have a problem with a uipangesturerecognizer when I zoom in the screen. My

  • 0

I have a problem with a uipangesturerecognizer when I zoom in the screen.

My App have a uiviewcontroller with a uiview.

In this view I have a calayer that is almost half of the entire screen bounds.

This calayer have several sublayers that the user can drag (uipangesture), add (uitapgesture) and remove (doubletapgesture). In order to drag more accurately I added to the uiview a uipinchgesture method to zoom in and out.

At this point everything works good except when I zoomed in and I try to move (pangesture) a sublayer. Sometimes works but usually not (without zooming in always works fine).

I don’t know if there is something wrong in my codes or may be this is not the way to do it. Is there anything that I miss?

I’m under sdk 4.2.

these are my codes:

    - (id)initWithFrame:(CGRect)frame
    {
        [super initWithFrame:frame]; 
        (…)
        perfil = [[CALayer alloc] init];        //the calayer of the uiview
        [perfil setBounds:CGRectMake(0, 0, wide, heigth/2)];
        [[self layer] addSublayer:perfil];

        //I add the sublayers to the "peril" layer when the user touch an "edit button" and that works fine

        //UIGsture Recognizers
        UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom:)];
        UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapFrom:)];
        UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchFrom:)];
        UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanFrom:)];
        [panGestureRecognizer setMinimumNumberOfTouches:1];
        [panGestureRecognizer setMaximumNumberOfTouches:1];
        [singleTapRecognizer setNumberOfTapsRequired:1];
        [singleTapRecognizer setCancelsTouchesInView:NO];
        [doubleTapRecognizer setNumberOfTapsRequired:2];

        [self addGestureRecognizer:singleTapRecognizer];
        [self addGestureRecognizer:doubleTapRecognizer];
        [self addGestureRecognizer:pinchGestureRecognizer];
        [self addGestureRecognizer:panGestureRecognizer];

        [singleTapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer];
        singleTapRecognizer.delegate = self;
        doubleTapRecognizer.delegate = self;
        pinchGestureRecognizer.delegate = self;
        panGestureRecognizer.delegate = self;

        //Some other different stuff here
    }


    - (void) handlePanFrom: (id)sender
    {
        CGPoint point = [(UIPanGestureRecognizer*)sender locationInView:self];
        boxLayer = [[self perfil] hitTest:point];
        [self becomeFirstResponder];

        if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan)
        {
            numberOfSublayer = 1000;    //declared as a int in UIView.h

            for (CALayer *elements in [perfil sublayers])
            {   
                if([boxLayer isEqual:elements])
                {
                    numberOfSublayer = [[perfil sublayers] indexOfObject:elements];
                    break;
                }
            }
        }
        (…) //Some more operations once I found the sublayer
    }


    - (void) handlePinchFrom: (id)sender
    {   
        if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded)
        {
            lastScale = 1.0;
            return;
        }

        if ([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan || 
            [(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateChanged) {

            CGFloat currentScale = [[[sender view].layer valueForKeyPath:@"transform.scale"] floatValue];

            const CGFloat kMaxScale = 4.0;
            const CGFloat kMinScale = 1.0;

            CGFloat newScale = 1 -  (lastScale - [(UIPinchGestureRecognizer*)sender scale]); 
            newScale = MIN(newScale, kMaxScale / currentScale);   
            newScale = MAX(newScale, kMinScale / currentScale);
            CGAffineTransform transform = CGAffineTransformScale([[sender view] transform], newScale, newScale);
            [sender view].transform = transform;

            if ([perfil sublayers])
            {
                for (CALayer *elements in [perfil sublayers])  //Here I try to adjust the zoom to the sublayers
                {
                    //Here is one first approach
                    //CGAffineTransform transformELS = CGAffineTransformScale([elements affineTransform], 7/(newScale+6), 7/(newScale+6));
                    //[elements setAffineTransform:transformELS];

                    //Here is a second approach
                    [elements setBounds:CGRectMake(0, 0, elements.bounds.size.width*7/(newScale+6), elements.bounds.size.height*7/(newScale+6))];
                }           
            }

            lastScale = [(UIPinchGestureRecognizer*)sender scale];
            (…) //Some other different stuff here
    }

Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:42:32+00:00Added an answer on June 6, 2026 at 5:42 am

    Finally I’ve found the answer to my problem. This post explains exactly the same issue and it’s solutions have worked perfectly for me
    UIPanGestureRecognizer starting point is off . Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Background view (UIImageView) in that i am adding a view(UIView). this
I have a view hierarchy that looks something like this: UIView (A) UIView >
I have an iPad app where I have a view controller that is the
I have this code for gesture in a view - (void)rightSwipeHandle:(UIPanGestureRecognizer*)gestureRecognizer{ CGPoint touchBegan; CGPoint
i have problem with showing an UIView on app delegate ... there is no
I have problem with my query on C, I’m using the oci8 driver. This
I have a simple app where I attach a UIPinchGestureRecognizer and UIPanGestureRecognizer to an
I have a main view that divided into 4 equally sized sub-views. I used
i have problem to pass data from view to controller , i have view
I have a test app for iOS that is built without any nib/xib files.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.