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

  • Home
  • SEARCH
  • 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 6699743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:43:54+00:00 2026-05-26T06:43:54+00:00

I have an object that the user has to drag around the screen. This

  • 0

I have an object that the user has to drag around the screen. This is a regular UIImageView. Currently, the image can be dragged around but when you release it, it stops where your finger lifted the image. What I want is to create momentum, so I can give an impulse to the image and it scrolls until it bounces the screen edge.

I don’t want nothing very complex like adding physics libraries and stuff like that. I want to keep it as minimum as possible.

How do I do that? Can you guys point me to some tutorial or in the right direction?

thanks.

  • 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-26T06:43:54+00:00Added an answer on May 26, 2026 at 6:43 am

    Well one way of doing this without using any physics library is this:

    First in your class create 4 instance variables like this:

    CFTimeInterval startTime;
    CGPoint startPoint;
    CGPoint oldPoint;
    BOOL imageViewTouched;
    

    Than in your - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event method have this code:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [[event allTouched] anyObject];
        // Test to see if the touched view is your image view. If not just return.
        if (touch.view != <#yourImageView#>) {
            return;
        }
    
        startPoint = [touch locationInView:self.view];
        oldPoint = startPoint;
        startTime = CACurrentMediaTime();
        imageViewTouched = YES;
    }
    

    For - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event do this:

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        // Fingers were moved on the screen but your image view was not touched in the beginning
        if (!imageViewTouched) {
            return;
        }
    
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint newPoint = [touch locationInView:self.view];
    
        <#yourImageView#>.frame = CGRectOffset(<#yourImageView#>.frame, newPoint.x - oldPoint.x, newPoint.y - oldPoint.y);
        oldPoint = newPoint;
    }
    

    Now for - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event try this:

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        // Fingers were removed from the screen but your image view was not touched in the beginning
        if (!imageViewTouched) {
            return;
        }
    
        imageViewTouched = NO;
    
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint endPoint = [touch locationInView:self.view];
        CFTimeInterval endTime = CACurrentMediaTime();
    
        CFTimeInterval timeDifference = endTime - startTime;
    
        // You may play with this value until you get your desired effect
        CGFloat maxSpeed = 80;
    
        CGFloat deltaX = 0;
        CGFloat deltaY = 0;
    
        if (timeDifference < 0.35) {
            deltaX = (endPoint.x - startPoint.x) / (timeDifference * 10);
            deltaY = (endPoint.y - startPoint.y) / (timeDifference * 10);
        }
    
        if      (deltaX > maxSpeed)         { deltaX =  maxSpeed; }
        else if (deltaX < -maxSpeed)        { deltaX = -maxSpeed; }
        else if (deltaX > -5 && deltaX < 5) { deltaX = 0; }
    
        if      (deltaY > maxSpeed)         { deltaY =  maxSpeed; }
        else if (deltaY < -maxSpeed)        { deltaY = -maxSpeed; }
        else if (deltaY > -5 && deltaY < 5) { deltaY = 0; }
    
        [UIView begginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5f];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
        <#yourImageView#>.frame = CGRectOffset(<#yourImageView#>.frame, deltaX, deltaY);
    
        [UIView commitAnimations];
    }
    

    Please let me know if this makes sense and/or works for you. Cheers!

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

Sidebar

Related Questions

I have an User object that has many attributes. In my edit profile screen
So I have a model called Image that belongs_to :user. Each user has a
I have an object User that has attributes whose accessability is declared as protected
I have a NSTimer object that I need to invalidate if a user taps
I have a function that loads a user object from a web service asynchronously.
I have the following code that loads a user's Active Directory DirectoryEntry object from
I have a form that is bind to an object, and when the user
I have two tables: object that has object_id column and avalues that have object_id
I have an object, based on the Singleton design, that I use for user
I have a small app that has a Render thread. All this thread does

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.