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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:17:30+00:00 2026-06-09T03:17:30+00:00

I am playing with XCode at the moment, but have no experience with Objective-C

  • 0

I am playing with XCode at the moment, but have no experience with Objective-C / Cocoa Touch etc so bear with me if this is a terribly rudimentary question. I only ask you guys because I’ve been trying to Google an answer for days, and am getting bored of dead ends.

I am trying to create a horizontally panning menu.

I am currently holding 3 UILabels inside a master UIView object, which is attached to a UIPanGestureRecognizer.

I have used a handlePan method to receive and translate the *menuview UIView object according to the user’s pan gesture, but I need to find the UIView‘s center coordinates when the PanGesture is released to calculate where to snap the UIView element back/forward to.

- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, 150);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];

if(recognizer.state == UIGestureRecognizerStateEnded)
{
    if(recognizer.view.center.x >= 576);{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        menuview.transform = CGAffineTransformMakeTranslation((764 - menuview.center.x), 0);
        [UIView commitAnimations];

    }

    if(recognizer.view.center.x && menuview.center.x >= 264);{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        menuview.transform = CGAffineTransformMakeTranslation((406 - menuview.center.x), 0);
        [UIView commitAnimations];

    }

    if(recognizer.view.center.x < 264);{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        menuview.transform = CGAffineTransformMakeTranslation((122 - menuview.center.x), 0);
        [UIView commitAnimations];

    }

}

}

You see I was trying to snap to one of three points on the x-axis, depending on where the center of the UIView is when the user releases their PanGesture.

At the moment, it is acting as if it’s ignoring the “recognizer.view.center.x” if statements, as no matter where it is released it snaps to x=122 (122 – menuview.center.x).

I have tried these if statements with:

if(menuview.center.x >= 576);{... 

etc, but that also fails.

What do I need to be putting in these if statements to create actions based ont he UIViews CURRENT position when the user releases their PanGesture?

Thanks,

Chris

  • 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-09T03:17:33+00:00Added an answer on June 9, 2026 at 3:17 am

    This is what I use, hopefully it will help you:

    .h

    #import <QuartzCore/QuartzCore.h>
    

    delcare these two floats

    float firstX;
    float firstY;
    

    .m

    -(void)moveHorizontallyAndVertically:(id)sender {
    [[[(UITapGestureRecognizer*)sender view] layer] removeAllAnimations];
    
    //  [self.view bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]];
    CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
    if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
        firstX = [myView center].x;
        firstY = [myView center].y;
    
    
    }
    
    translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);
    
    [myView setCenter:translatedPoint];
    
    if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
        CGFloat finalX = translatedPoint.x + (0.0*[(UIPanGestureRecognizer*)sender velocityInView:self.view].x);
        CGFloat finalY = translatedPoint.y + (0.0*[(UIPanGestureRecognizer*)sender velocityInView:self.view].y);
        if(finalX < 0) {
            finalX = 0;
        }
        else if(finalX > 320) {
            finalX = 320;
        }
        if(finalY < 0) {
            finalY = 0;
        }
        else if(finalY > 480) {
            finalY = 480;
        }
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [myView setCenter:CGPointMake(finalX, finalY)];
        [UIView commitAnimations];
    }
    

    }

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

Sidebar

Related Questions

I have been playing around with Xcode lately and am stuck at this stupid
I am using Xcode 4.3 and i have a problem with playing sound... I
Im new to xCode programming, ive got this code from an ebook tutorial playing
I am playing with my Xcode, following tutorial, learning this stuff. I added an
I am playing around with clucene under mac osx with xcode and have some
So basically i have upgraded to iOS5 and xcode 4.2 but after a little
I just told Xcode to compile everything as Objective-C++ and now I have errors
Have started playing with Xcode 4.2, and created a single page application using storyboard
I have just started playing with storyboards in XCode 4.3 and while designing an
Playing with the new(ish) url rewriting functionality for web forms, but I'm running into

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.