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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:47:29+00:00 2026-06-15T06:47:29+00:00

I am building an iphone app that has multiple UIViews in a 3×3 matrix

  • 0

I am building an iphone app that has multiple UIViews in a 3×3 matrix (so total of 9 UIViews) within one UIViewController. I am trying to find a way to let the user move one view to a location in the matrix which will then rearrange the rest of the views accordingly. Think of when you drag an app on your springboard to another place and all the other icons arrange themselves accordingly.

What is the best way to accomplish something like 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-06-15T06:47:30+00:00Added an answer on June 15, 2026 at 6:47 am

    Use UIPanGestureRecognizer, using the translationInView to adjust the coordinates of the item you’re dragging. For a discussion of gesture recognizers, see the Event Handling Guide for iOS.

    When you let go (i.e. the gesture ends), you can use UIView class method animateWithDuration to animate the moving of various items to their final locations.

    So, in viewDidLoad, you might do something like the following (assuming that you had your nine controls in an array called arrayOfViews):

    for (UIView *subview in self.arrayOfViews)
    {
        UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] initWithTarget:self  
                                                                                  action:@selector(movePiece:)];
        [subview addGestureRecognizer:gesture];
    }
    

    And then your gesture recognizer handler might look like:

    - (void)movePiece:(UIPanGestureRecognizer *)gesture
    {
        static CGPoint originalCenter;
    
        if (gesture.state == UIGestureRecognizerStateBegan)
        {
            originalCenter = gesture.view.center;
        }
        else if (gesture.state == UIGestureRecognizerStateChanged)
        {
            CGPoint translation = [gesture translationInView:self.view];
    
            gesture.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y + translation.y);
        }
        else if (gesture.state == UIGestureRecognizerStateEnded)
        {
            [UIView animateWithDuration:0.25
                             animations:^{
    
                // move your views to their final resting places here
            }];
        }
    }
    

    This is the bare-bones of what a dragging of controls around might look like.

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

Sidebar

Related Questions

I'm pretty new to iPhone development. I am building an app which has multiple
I'm building an iPhone app that has to download an Excel (.xls) file from
I am building an app for iPhone that has JavaScript running in a webview.
I am building an iPhone app that has some default data inside it via
I am building an iphone app that has a small button at the right
I am building an iPhone app that will need to display info primarily in
I'm building an iPhone app version of a website that sells tickets online. I'm
I'm building an app that allows users to snap pictures using the iPhone camera,
I am building an iPhone app, and I am trying to have a web
I have an app that I'm building with XCode 4.2. It has push, and

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.