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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:07:30+00:00 2026-06-12T10:07:30+00:00

I have an object that is moving right to left across the screen: [UIView

  • 0

I have an object that is moving right to left across the screen:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:7.8];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
 myImageview.layer.position = CGPointMake(20,  myImageView.layer.position.y);
[UIView commitAnimations];

I found out that even while the animation is still happening, XCode already marks the image’s location as its final destination, and in order to detect a touch on the moving image, I need to use the presentationLayer:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [super touchesBegan:touches withEvent:event];

    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self.view];

    if ([myImageview.layer.presentationLayer hitTest:touchPoint]) {
        NSLog(@"it's a hit!");
    }
}

This part works.
Now, I’d like the image to move up when it is pressed.
I want the image to move up while it continues it’s sideways movement.
Instead, this code moves the image not just up, but also all the way to its final destination on the left:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [super touchesBegan:touches withEvent:event];

    UITouch *touch = [touches anyObject];   
    CGPoint touchPoint = [touch locationInView:self.view];

    if ([mouse.layer.presentationLayer hitTest:touchPoint]) {
        NSLog(@"it's a hit!");
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        myImageView.layer.position = CGPointMake( mouse.layer.position.x,  myImageView.layer.position.y - 40);
        [UIView commitAnimations];
    }
}

I want the image to move up while it continues it’s sideways movement.
Does anyone know of a way to accomplish this?

Thanks so much!

  • 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-12T10:07:31+00:00Added an answer on June 12, 2026 at 10:07 am

    Have you tried setting the animation option UIViewAnimationOptionBeginFromCurrentState?

    (I say option because it is an option in the block-based animation methods introduced with iOS 4. It is also available as [UIView setAnimationBeginsFromCurrentState:YES] if you can’t switch away from the deprecated UIView class methods just yet.)

    touchesBegan becomes (using block animations):

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
        [super touchesBegan:touches withEvent:event];
    
        UITouch *touch = [touches anyObject];   
        CGPoint touchPoint = [touch locationInView:self.view];
    
        if ([mouse.layer.presentationLayer hitTest:touchPoint]) {
            NSLog(@"it's a hit!");
            [UIView animateWithDuration:0.5 delay:0.0 options:(UIViewAnimationOptionCurveLinear & UIViewAnimationOptionBeginFromCurrentState) animations:^{
                myImageView.layer.position = CGPointMake( myImageView.layer.position.x,  mouse.layer.position.y - 40);
            }completion:^(BOOL complete){
                //
            }];
        }
    }
    

    If you use that you should be able to specify the final x and y coordinates you want and have animation proceed from the point at which the object was touched to that position.

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

Sidebar

Related Questions

I have an object that returns a value if successful and false (or nil)
I have an object that travels on the screen and I was just wondering
I have an object called point that I can move around the screen with
I have two tables: object that has object_id column and avalues that have object_id
I have an object that cannot be copied, a NetGame because it has a
I have an object that has pairs of replacement values used for simple encoding
I have an object that looks like this { AF : { name :
I have an object that I convert into NSData using an NSKeyedArchiver and then
I have an object that has properties, but when I try to access them,
I have some object that's been added to the body of my page via

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.