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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:11:12+00:00 2026-06-03T05:11:12+00:00

Aloha everyone, I have a background image with a grid layout and would like

  • 0

Aloha everyone,
I have a background image with a grid layout and would like to allow the user to move one of a set of buttons to specific grid locations, but only to those specific locations. In other words, say I wanted to limit the movement on the y axis to increments of, say 65 pixels, then snap the button to the closest point (if you moved it 67 pixels, it would snap back 2 pixels). Does anyone know how to accomplish this?

  • 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-03T05:11:13+00:00Added an answer on June 3, 2026 at 5:11 am

    Below is some code I’m currently working with, it allows the user to drag and drop an image around the screen. You’ll notice the “if” statements with values set to “960” and “640” and such, this states that if the user attempts to drag the image off screen it animates the image moving back into the screen and can be easily modified to make the image move to the closest grid coordinate that the user dropped in near.

    - (void)callMarkerFourteen
    {
    
        UIImage *image = [UIImage imageNamed:@"VerticalLine.png"];
    
        markerViewFourteen = [[UIView alloc] initWithFrame:CGRectMake(160, 210, 40, image.size.height)];
        [markerViewFourteen setBackgroundColor:[UIColor colorWithRed:255 green:0 blue:0 alpha:.5]];
        markerImageViewFourteen = [[UIImageView alloc] initWithFrame:[markerViewFourteen frame]];
        [markerImageViewFourteen setFrame:CGRectMake(18, 0, 4, 100)];
        [markerImageViewFourteen setImage:image];
        [markerViewFourteen addSubview:markerImageViewFourteen];
    
        UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
        [panRecognizer setMinimumNumberOfTouches:1];
        [panRecognizer setMaximumNumberOfTouches:1];
        [panRecognizer setDelegate:self];
        [markerViewFourteen addGestureRecognizer:panRecognizer];
    
        [self.view addSubview:markerViewFourteen];
    }
    
    
    -(void)move:(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 = [[sender view] center].x;
            firstY = [[sender view] center].y;
        }
    
        translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);
    
        [[sender view] 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(UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
    
                if(finalX < 0) {                                
                    finalX = 0;             
                }                           
                else if(finalX > 640) {
    
                    finalX = 640;
                }
    
                if(finalY < 0) {                                
                    finalY = 0;             
                }                       
                else if(finalY > 960) {
    
                    finalY = 960;
                }
            }
    
            else {
    
                if(finalX < 0) {                                
                    finalX = 0;             
                }                       
                else if(finalX > 960) {
    
                    finalX = 640;
                }
    
                if(finalY < 0) {                                
                    finalY = 0;             
                }                       
                else if(finalY > 640) {
    
                    finalY = 960;
                }
            }
    
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:.35];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            [[sender view] 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

Aloha-everyone, I would like to to know how to convert a memory content of
Is there a plugin for Aloha Editor that would let the user add audio/video
Aloha everyone, I have a class assignment in which I am tasked to build
Aloha everyone, I have another question. I have a SYDI script that retrieves WMI
Aloha everyone, I have created a small bash shell script which I wanted to
Aloha I have a VS2008 solution to which I want to add a webservice
Aloha I have a method with (pseudo) signature: public static T Parse<T>(string datadictionary) where
Aloha I received a nice wsdl with xs: documentation tags like: <xs:complexType name=Supplier> <xs:annotation>
I need same menu like on this site http://www.salesforce.com/aloha.jsp in wordpress theme. Multilevel dropdown
Aloha, how do I determine/calculate whether an image aspect ratio is appropriate (proportion) in

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.