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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:35:41+00:00 2026-05-25T10:35:41+00:00

I am moving a few CALayers using the -mouseDragged method, and now I would

  • 0

I am moving a few CALayers using the -mouseDragged method, and now I would like to “snap” them when they are sufficiently near (or when they are overlapping just a little bit).
Each layer is not a “square”: I am drawing different polygons.

I thought that a way to do this is to:

  1. get the position of the layer being moved;
  2. get the overlapping layers or the layers that are near the layer being moved;
  3. On each side of the polygon in which (2) is true, I need to check the maximum distance (at right angles to the side of the layer) between the side of the moving layer and the side of the layer that is “near” (this is a negative value when the layers overlap).
  4. move the layer accordingly.

I don’t know if this is a correct approach. The first thing that comes in my mind is:

  • What happens if I can “snap” in more than one side?

And, even if I try this way, I have no idea what to do regarding (2) and (3).

Is there a better way to do 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-25T10:35:41+00:00Added an answer on May 25, 2026 at 10:35 am

    This is not easy. Because CALayers are not vector graphics you have to deal with any possible shape (eg. picture of a dragon.)

    Proper collisions are difficult. Instead try hit testing the mouse/touch’s position with the shape you want to snap to.

    You can do this by checking the transparency of each of the possible snapping layers at the mouse location. See this question for information of how to do this.

    More Difficult but Better Results:

    Use a 2D physics engine like Chipmunk or Box2D to do your collision detection.

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

Sidebar

Related Questions

I am moving from the basic authentication method using username and password to the
A client is moving from their old hosting to mine. They have a few
I am tasked with moving quite a few web apps including the databases to
As a win32 developer moving into web deveopment the last few years, I found
I am moving a few functions from a Managed C++ Winforms app to a
Background: I'm moving my application from npgsql v1 to npgsql v2.0.9. After a few
I am moving now from VS 2005 to VS 2010 with products consisting of
I spent the last few hours moving my /home to its own partition, and
I'm a few weeks into moving all of our source code into an SVN
I am working on some migration project, involves moving around quite a few stuff

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.