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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:44:36+00:00 2026-06-03T20:44:36+00:00

I have the following code in my app which I could just copy and

  • 0

I have the following code in my app which I could just copy and paste each time, but I would rather make it so it is reusable in other areas too. It allows me to drag UIImageViews around the screen but I don’t like the fact that it is very prone to error with the slightest of typos!

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];




if (touch.view == first) {
    first.center = location;

    if (((first.center.x >= 100) && (first.center.y >= 100) &&
         (first.center.x <= 150) && (first.center.y <= 150))) {

        first.center = CGPointMake(125, 125);
        [first setUserInteractionEnabled:NO];

        theCentre = [[NSUserDefaults standardUserDefaults] init];

        NSString *centre = NSStringFromCGPoint(first.center);

        [theCentre setObject:centre forKey:@"centre"];

        //  NSLog(@"%@", [theCentre objectForKey:@"centre"]);
        [theCentre synchronize];

    }

}
if (touch.view == second) {
    second.center = location;

    if (((second.center.x >= 150) && (second.center.y >= 150) &&
         (second.center.x <= 180) && (second.center.y <= 180))) {

        second.center = CGPointMake(165, 165);
        [second setUserInteractionEnabled:NO];

        theCentre = [[NSUserDefaults standardUserDefaults] init];

        NSString *centre = NSStringFromCGPoint(second.center);

        [theCentre setObject:centre forKey:@"secondCentre"];

        //  NSLog(@"%@", [theCentre objectForKey:@"centre"]);
        [theCentre synchronize];
}
}
if (touch.view == third) {
    third.center = location;

    if (((third.center.x >= 200) && (third.center.y >= 200) &&
         (third.center.x <= 230) && (third.center.y <= 230))) {

        third.center = CGPointMake(215, 215);
        [third setUserInteractionEnabled:NO];

        theCentre = [[NSUserDefaults standardUserDefaults] init];

        NSString *centre = NSStringFromCGPoint(third.center);

        [theCentre setObject:centre forKey:@"thirdCentre"];

        //  NSLog(@"%@", [theCentre objectForKey:@"centre"]);
        [theCentre synchronize];
    }

}  

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}

I have tried fast enumeration but that made one imageView move and the others just disappear off the screen! Obviously not the desired effect…

  • 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-03T20:44:39+00:00Added an answer on June 3, 2026 at 8:44 pm

    I recommend using UIGestureRecognizers for this. After you set up your image views write:

    NSArray *imageViews = [NSArray arrayWithObjects:first, second, third, nil];
    for (UIView *imageView in imageViews) {
        UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] 
            initWithTarget:self action:@selector(handlePanGesture:)]
        [imageView addGestureRecognizer:panGR];
        [panGR release];
    }
    

    And then implement the gesture handler:

    - (void)handlePanGesture:(UIGestureRecognizer *)gestureRecognizer {
        UIPanGestureRecognizer *panGR = (UIPanGestureRecognizer *)gestureRecognizer;
        UIView *gestureView = [panGR view];
        CGPoint translation = [panGR translationInView:gestureView];
        gestureView.center = CGPointMake(gestureView.center.x + translation.x,
                                         gestureView.center.y + translation.y);
        [panGR setTranslation:CGPointZero inView:gestureView];
    }
    

    This code is untested (written in notepad), but this is the right direction.

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

Sidebar

Related Questions

In my Zend Framework app, I have following code: index.php $app_started_time = time(); layout.phtml
Let's say I have the following code in Google App Engine: from urllib import
I have the following code that allows my console app to go to the
I have the following code: <fx:Script> <![CDATA[ import shared.GlobalsManager; import app.Globals; protected var globals:Globals=GlobalsManager.getGlobals();
I am developing a Android app using Jquery Mobile/Phonegap. I have the following code
Im trying to get debugging working without an app.config. I have the following code:
So, I'm finishing up an iPhone App. I have the following code in place
I have the following section of code in an app that I am writing:
I have the following node.js server-side code: var app = require('http').createServer(handler) , io =
I have the following crash log and complete source code of app. All I

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.