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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:45:02+00:00 2026-05-19T03:45:02+00:00

i took a uiview application.i placed a image on the controller’s view.my requirement is

  • 0

i took a uiview application.i placed a image on the controller’s view.my requirement is the image should be movable with the help of mouse.mouse should select the image and the image should be moved as the mouse is dragged.the image movement should be restricted to only a particular portion of the view.
can someone help me code the desirable task
tnx in advance

dinakar

  • 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-19T03:45:03+00:00Added an answer on May 19, 2026 at 3:45 am

    This can be accomplished with touchesBegan and touchesMoved events.

    - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
    {
        // This gets you starting position of 
        UITouch *touch = [ [ event allTouches ] anyObject ] ;   
    
        float touchXBeginPoint = [ touch locationInView:touch.view ].x ;
        float touchYBeginPoint = [ touch locationInView:touch.view ].y ;
    
        // Calculate the offset between the current image center and the touched points.
        //  Moving image only along X - direction and try thinking as how to move in 
        // any direction using this as a reference. It isn't that hard.
    
        touchOffset = image.center.x - touchXBeginPoint ;
        // touchOffset should be a member variable of class or a variable with global scope
    
    } 
    
    - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        // Calculate the difference from previous position and the current position
        // Add this difference to the previous point and move the image center to that point.
        // How ever, you should have an UIImageView outlet connected on to the image placed
        // on the interface builder.
    
        // And regarding image movement restriction, since you always have co-ordinates with
        // you, you can set the boundaries.
    
        UITouch *touch = [ [ event allTouches ] anyObject ] ;
    
        float distanceMoved =( [ touch locationInView:touch.view ].x + touchOffset ) -  image.center.x  ;
        float newX = image.center.x + distanceMoved ;
    
        if( newX > 30 && newX < 290 ) // setting the boundaries
            image.center = CGPointMake(newX, image.center.y) ;
    }
    

    Hope this should be helpful.

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

Sidebar

Related Questions

All I need is to view a UIView controller in same storyboard file manually
It took me a while, and some help from Apple (one instruction I missed),
It took me a while to realize what was going on with mouse events
I took over some old php application with MySQL as database. Inside the database,
I took some code from my C# Windows form app which uses the Application
hii guys, i am working on a crossword application.I took UITextField to the respective
I took a training on BizTalk 2010 and found very help but I got
I took a JSP class and we learnt that we should always remove all
I took over an ASP.NET application and have found this throughout several classes in
I took a data structures class in C++ last year, and consequently implemented all

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.