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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:54:27+00:00 2026-05-29T14:54:27+00:00

I am looking to implement something in Objective-C for the IOS platform. I want

  • 0

I am looking to implement something in Objective-C for the IOS platform.

I want to have two GUI objects, let’s just say they are UIImages for simplicity and are square shapes.

And then I have an “empty” GUI element that is just a greyed out square of the same size.

I want the user to be able to drag one of the square images over to the empty square and as long as some part of the image is touching the empty square it will snap into that empty square and fill it up. And if they drop the image anywhere else it animates back to the original location.

As well I would want to have 2 other square images and another empty square such with the same interaction but each group of 2 images and 1 empty square can’t work between each other. i.e. the first two images can only be dropped into the first empty square.

I assume there would be some drop event I am looking to capture and then determine if the image meta data matches with the empty square it is being dropped into.

If you know of any code samples or apps out there I can certainly work through the code to understand or if you have some objects, events and properties to point me to that would be great.

This isn’t for a game as much as an app so I would prefer not to work in any of the game engines but if that is an easy way to do it then I am all for that.

  • 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-29T14:54:28+00:00Added an answer on May 29, 2026 at 2:54 pm

    You can achieve this fairly easily. To the image, you attach a UILongPressGestureRecognizer and in the action method, you update the image’s position based on finger movement. Get the gesture’s current location with - (CGPoint)locationInView:(UIView *). Upon every movement, you can check whether the image frame overlaps the frame of your target area and if it does, snap it into place.

    Checking for overlap is fairly simple (given image and target both are part of the same view hierarchy):

    CGRect imageRect = [image convertRect:image.frame toView:[image superview]];
    CGRect targetRect = [target convertRect:target.frame toView:[image superview]];
    if (CGRectIntersectsRect(imageRect, targetRect)) {
        // overlap
    }
    

    To move back the image if the user dropped outside, you can make a frame or center animation back to the original position. So, when the drag begins, your action method is called. You check whether your instance variable, let’s name it originalCenter, is not equal to CGPointZero. If it is, you record the current center into originalCenter.

    Then, when the user drops the image and it is outsize the target, you move it back:

    [UIView animateWithDuration:0.2
                     animations:^{
                         image.center = originalCenter;
                         self.originalCenter = CGPointZero;
                      }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to implement a continuous unit test running system, something I have
I am looking to implement something similar to facebook/gmail chat. I know they use
I was looking to implement something like the image below, and really have no
I am looking to implement something that appears to have shopping cart functionality, but
I'm looking to implement something in Java along the lines of: class Foo{ private
Looking to implement VisualSVN but I don't have my own server. I could install
I am looking for something in Objective C that creates an AST out of
I am trying to implement something using NET MF and was looking for a
I'm looking for an easy way to implement something like this: http://www.dinointeractive.com/?p=117 . And
I've just got confused how to implement something in a generic way in C++.

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.