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 9179079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:42:29+00:00 2026-06-17T17:42:29+00:00

I am trying to detect the touches in a UIPinchGestureRecognizer ‘s method, because I

  • 0

I am trying to detect the touches in a UIPinchGestureRecognizer‘s method, because I need both the horizontal and the vertical scale. On pinch, an image should be resized accordingly. For example if the user moves the fingers only horizontally, I am resizing only the width of the view.

It is working fine, but when I take my fingers of the screen, most of the times the app crashes with SIGABRT and no message.

My code is:

    if (recognizer.state == UIGestureRecognizerStateBegan) {
        previousHorizontalPinchDistance = ABS([recognizer locationOfTouch:1 inView:recognizer.view].x - [recognizer locationOfTouch:0 inView:recognizer.view].x);
        previousVerticalPinchDistance = ABS([recognizer locationOfTouch:1 inView:recognizer.view].y - [recognizer locationOfTouch:0 inView:recognizer.view].y);
    }
    CGFloat horizontalPinchDistance = ABS([recognizer locationOfTouch:1 inView:recognizer.view].x - [recognizer locationOfTouch:0 inView:recognizer.view].x);
    CGFloat verticalPinchDistance = ABS([recognizer locationOfTouch:1 inView:recognizer.view].y - [recognizer locationOfTouch:0 inView:recognizer.view].y);

The crash is at the line where I set the horizontalPinchDistance. Any idea why? Thanks!

  • 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-17T17:42:31+00:00Added an answer on June 17, 2026 at 5:42 pm

    In the meantime, I’ve found the reason for the crash.

    When the user lifts a finger, the Pinch recognizer’s method still gets called (or if the user doesn’t lift both fingers at the same time). The problem is that numberOfTouches becomes 1 instead of 2. So the index 1 in the method call [recognizer locationOfTouch:1 inView:recognizer.view] will be out of bounds. So the block of code in my question should only be executed if recognizer.numberOfTouches > 1.

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

Sidebar

Related Questions

I am trying to detect touches, but the touchesBegan method is not being called.
I'm using Cocos2d-x and trying to detect touches in my HelloWorld project. Though I'm
I am trying to detect when the laptop lid opens and closes, should be
I'm trying to create a extended CCSprite class that can detect touches. I have
I am trying to detect touches inside a subview In my main viewcontroller I
I'm trying to detect when a user touches down and up in a view.
I'm trying to make something where doing a pinch rotates an image, using the
I am trying to find a way to detect when a user touches the
I need to detect long touch in the game the game I am trying
I’m trying to detect an iOS 6-specific appearance method, by running respondsToSelector on the

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.