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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:32:12+00:00 2026-05-17T23:32:12+00:00

While I drag an uiimageview , the center is positioned at clickpoint..I am using

  • 0

While I drag an uiimageview, the center is positioned at clickpoint..I am using the following code

imageView.center=[[touches anyObject] locationInView:self.view];

so the mouse jumps to image center even I drag at the corner.

How can I make the mouse to position at clicked position of the imageview.???

Thanx in advance

  • 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-17T23:32:13+00:00Added an answer on May 17, 2026 at 11:32 pm

    I’m supposing you want to move your imageView and the imageView is moving its center to your touch point “unintentionally”…

    If you don’t want your imageView to set its center at the touch but be dragged from any point the user touhes it, keep track of the first CGPoint he touched, and then reposition your image at the relative distance between the previous two touchpoints

    @interface myViewController : UIViewController {
        CGPoint touchPoint;
        BOOL touchedInside;
    }
    @end
    
    @implementation myViewController
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        touchPoint = [touch locationInView:self.view];
        CGPoint pointInside = [touch locationInView:imageView];
        if ([imageView pointInside:pointInside withEvent:event])
            touchedInside = YES;
    }
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        if (touchedInside) {
            UITouch *touch = [touches anyObject];
            CGPoint newPoint = [touch locationInView:self.view];  // get the new touch location
            imageView.center = CGPointMake(imageView.center.x + newPoint.x - touchPoint.x, imageView.center.y + newPoint.y - touchPoint.y); // add the relative distances to the imageView.center
            touchPoint = newPoint;  // assign the newest touch location to the old one
        }
    }
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        touchedInside = NO;
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        if (touchedInside) {
            UITouch *touch = [touches anyObject];
            CGPoint newPoint = [touch locationInView:self.view];
    
            imageView.center = CGPointMake(imageView.center.x + newPoint.x - touchPoint.x, imageView.center.y + newPoint.y - touchPoint.y);
        }   
        touchedInside = NO;
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a simple drag/drop of images between panels using jQuery. While
While going through university and from following the development of SO, I've heard a
While I grew up using MSWindows, I transitioned to my much-loved Mac years ago.
I'm trying to drag a UIImageView according to an anchorPoint but the whole image
I'm using YUI to add drag drop support to a div. It also responds
How can I show tooltips while performing drag-n-drop. It seems that tooltip display during
I have used jQuery UI library to drag divs within a web page. While
I have a WPF 4 application where I have implemented Drag and Drop using
Is it possible to drag UIView around the iOS screen while it has both
i am working on a html5 interface wich uses drag and drop. While 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.