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

  • Home
  • SEARCH
  • 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 6798219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:42:14+00:00 2026-05-26T18:42:14+00:00

Here is my code: viewDidLoad: UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)]; [self.canvas addGestureRecognizer:pinch]; pinch.delegate

  • 0

Here is my code:

viewDidLoad:

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
[self.canvas addGestureRecognizer:pinch];
pinch.delegate = self;

UIRotationGestureRecognizer *twoFingersRotate = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(pinchRotate:)];
[[self canvas] addGestureRecognizer:twoFingersRotate];

twoFingersRotate.delegate = self;

Code For Pinches and Rotates:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

-(void)pinchRotate:(UIRotationGestureRecognizer*)rotate
{
    SMImage *selectedImage = [DataCenter sharedDataCenter].selectedImage;

    switch (rotate.state) 
    {
        case UIGestureRecognizerStateBegan:
        {
            selectedImage.referenceTransform = selectedImage.transform;
            break;
        }
        case UIGestureRecognizerStateChanged:
        {
            selectedImage.transform = CGAffineTransformRotate(selectedImage.referenceTransform, ([rotate rotation] * 55) * M_PI/180);
            break;
        }

        default:
            break;
    }
}

-(void)pinch:(UIPinchGestureRecognizer*)pinch
{
    SMImage *selectedImage = [DataCenter sharedDataCenter].selectedImage;
    [self itemSelected];

    switch (pinch.state) 
    {
        case UIGestureRecognizerStateBegan:
        {
            selectedImage.referenceTransform = selectedImage.transform;
            break;
        }
        case UIGestureRecognizerStateChanged:
        {
            CGAffineTransform transform = CGAffineTransformScale(selectedImage.referenceTransform, pinch.scale, pinch.scale);
            selectedImage.transform = transform;
            break;
        }

        default:
            break;
    }
}

My rotation works great on its own and my scale works great on its own, but they wont work together. One always works or the other doesn’t. When I implement shouldRecognizeSimultaneouslyWithGestureRecognizer the two gestures seem to fight against each other and produce poor results. What am I missing? (Yes I have implemented <UIGestureRecognizerDelegate>)

  • 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-05-26T18:42:14+00:00Added an answer on May 26, 2026 at 6:42 pm

    Every time pinch: is called, you just compute the transform based on the pinch recognizer’s scale. Every time pinchRotate: is called, you just compute the transform based on the rotation recognizer’s rotation. You never combine the scale and the rotation into one transform.

    Here’s an approach. Give yourself one new instance variable, _activeRecognizers:

    NSMutableSet *_activeRecognizers;
    

    Initialize it in viewDidLoad:

    _activeRecognizers = [NSMutableSet set];
    

    Use one method as the action for both recognizers:

    - (IBAction)handleGesture:(UIGestureRecognizer *)recognizer
    {
        SMImage *selectedImage = [DataCenter sharedDataCenter].selectedImage;
    
        switch (recognizer.state) {
            case UIGestureRecognizerStateBegan:
                if (_activeRecognizers.count == 0)
                    selectedImage.referenceTransform = selectedImage.transform;
                [_activeRecognizers addObject:recognizer];
                break;
    
            case UIGestureRecognizerStateEnded:
                selectedImage.referenceTransform = [self applyRecognizer:recognizer toTransform:selectedImage.referenceTransform];
                [_activeRecognizers removeObject:recognizer];
                break;
    
            case UIGestureRecognizerStateChanged: {
                CGAffineTransform transform = selectedImage.referenceTransform;
                for (UIGestureRecognizer *recognizer in _activeRecognizers)
                    transform = [self applyRecognizer:recognizer toTransform:transform];
                selectedImage.transform = transform;
                break;
            }
    
            default:
                break;
        }
    }
    

    You’ll need this helper method:

    - (CGAffineTransform)applyRecognizer:(UIGestureRecognizer *)recognizer toTransform:(CGAffineTransform)transform
    {
        if ([recognizer respondsToSelector:@selector(rotation)])
            return CGAffineTransformRotate(transform, [(UIRotationGestureRecognizer *)recognizer rotation]);
        else if ([recognizer respondsToSelector:@selector(scale)]) {
            CGFloat scale = [(UIPinchGestureRecognizer *)recognizer scale];
            return CGAffineTransformScale(transform, scale, scale);
        }
        else
            return transform;
    }
    

    This works if you’re just allowing rotating and scaling. (I even tested it!)

    If you want to add panning, use a separate action method and just adjust selectedImage.center. Trying to do panning with rotation and scaling using selectedImage.transform is much more complicated.

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

Sidebar

Related Questions

here is the code - (void)viewDidLoad { hauptOptionen = [[NSMutableArray alloc] init]; self.hauptOptionen =
so here's the abridged code: - (void)viewDidLoad { [super viewDidLoad]; currentLocation = [[UITextField alloc]
Here's the code: - (void)viewDidLoad { [super viewDidLoad]; NSURL *musicURL = [NSURL URLWithString:@http://live-three2.dmd2.ch/buureradio/buureradio.m3u]; if([musicURL
Here is my code: NSRegularExpression * regex; - (void)viewDidLoad { NSError *error = NULL;
I'm trying to scroll the pdf file by page here is my code -(void)viewDidLoad{
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code from MSDN . I don't understand why the work isn't just
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
enter code here I have a table on SQL server 2005 with bigint primary
The code here is X++. I know very little about it, though I am

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.