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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:11:33+00:00 2026-06-04T16:11:33+00:00

I have come to SO with a question after a long time, I haven’t

  • 0

I have come to SO with a question after a long time, I haven’t learned enough yet :(.

I am having a UIScrollView which has UIImageView inside it. The image of the UIImageView is to change with a right and left swipe. I know overriding the touches of UIScrollView will not be a good and efficient solution, so I added a transparent view upon the UIScrollView (not as its subview) covering the bounds of UIScrollView and overridden its touch methods to change the images on swipe.

Now with the help of pinch gesture recognizer added to my transparent view I am able to zoom the UIScrollView and the image programmatically. Till here, I am able to work the things smoothly but I have another typical functionality. I have to move the zoomed image with my finger up and down so that I can see the cropped image. I am doing it with the help of UILongPressGestureRecognizer added to my transparent view. Upon 1 seconds of touch duration I add a UIImageView with a four way arrow image and add it touch location. Now as I move my finger, the fourwayarrow image follows my finger but the image in the scrollview does not follow my finger. Its kind of jerky and often works like I have tied an elastic string. So initially I have to pull the string to some threshold (till that point the scroll view does not move) and when it reaches that level, it suddenly starts moving out of control. I am adding the code here for you people to have a look.

Please feel free to add comments if you people need any other information.

- (void) handleLongPress:(UILongPressGestureRecognizer *)longPressGestureRecognizer{
    CGPoint touchLocation = [longPressGestureRecognizer locationInView:self.transparentLayer];
    switch (longPressGestureRecognizer.state) {
        case UIGestureRecognizerStatePossible: break;
        case UIGestureRecognizerStateBegan:{
            if (fourWayArrowImageView == nil) {
                fourWayArrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"4wayarrow.png"]];
                [fourWayArrowImageView setBackgroundColor:[UIColor clearColor]];
            }
            _previousLocation.x = touchLocation.x;
            _previousLocation.y = touchLocation.y;
            [fourWayArrowImageView setCenter:touchLocation];
            [self.transparentLayer addSubview:fourWayArrowImageView];
        }
            break;
        case UIGestureRecognizerStateChanged:{
            float dx = (touchLocation.x - _previousLocation.x);
            float dy = (touchLocation.y - _previousLocation.y);
            CGPoint currentMaxOffset = [self currentMaxOffset];
            CGPoint currentOffset = [self.rotatableImageViewContainingScrollView contentOffset];
            float theScale = [self.rotatableImageViewContainingScrollView zoomScale];
            currentOffset.x -= (dx*theScale);
            currentOffset.y -= (dy*theScale);

            [fourWayArrowImageView setCenter:touchLocation];
            CGSize size = self.rotatableImageViewContainingScrollView.frame.size;
            [self.rotatableImageViewContainingScrollView scrollRectToVisible:CGRectMake(currentOffset.x, currentOffset.y, size.width, size.height) animated:YES];
            _prevMaxOffset = CGPointMake(currentMaxOffset.x, currentMaxOffset.y);
        }
            break;
        case UIGestureRecognizerStateCancelled:
        case UIGestureRecognizerStateFailed:
        case UIGestureRecognizerStateEnded: [fourWayArrowImageView removeFromSuperview]; break;
    }
}
  • 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-04T16:11:35+00:00Added an answer on June 4, 2026 at 4:11 pm

    Found the solution. Actually I was doing a mistake. I was not updating the previous location after the scrolling and the scrolling should not be animated in this case. So please look at the answer. BTW thanks to all guys who gave time:

    - (void) handleLongPress:(UILongPressGestureRecognizer *)longPressGestureRecognizer{
        CGPoint touchLocation = [longPressGestureRecognizer locationInView:self.transparentLayer];
        switch (longPressGestureRecognizer.state) {
            case UIGestureRecognizerStatePossible: break;
            case UIGestureRecognizerStateBegan:{
                if (fourWayArrowImageView == nil) {
                    fourWayArrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"4wayarrow.png"]];
                    [fourWayArrowImageView setBackgroundColor:[UIColor clearColor]];
                }
                _previousLocation = CGPointMake(touchLocation.x, touchLocation.y);
                [fourWayArrowImageView setCenter:touchLocation];
                [self.transparentLayer addSubview:fourWayArrowImageView];
            }
                break;
            case UIGestureRecognizerStateChanged:{
                float dx = (touchLocation.x - _previousLocation.x);
                float dy = (touchLocation.y - _previousLocation.y);
                CGPoint currentMaxOffset = [self currentMaxOffset];
                CGPoint currentOffset = [self.rotatableImageViewContainingScrollView contentOffset];
                //float theScale = [self.rotatableImageViewContainingScrollView zoomScale];
                //currentOffset.x -= (dx*theScale);
                //currentOffset.y -= (dy*theScale);
                currentOffset.x -= (dx);
                currentOffset.y -= (dy);
                [fourWayArrowImageView setCenter:touchLocation];
                CGSize size = self.rotatableImageViewContainingScrollView.frame.size;
                [self.rotatableImageViewContainingScrollView scrollRectToVisible:CGRectMake(currentOffset.x, currentOffset.y, size.width, size.height) animated:NO]; //bool value in animated should be false.
                _prevMaxOffset = CGPointMake(currentMaxOffset.x, currentMaxOffset.y);
                _previousLocation = CGPointMake(touchLocation.x, touchLocation.y); // added this line in the answer.
            }
                break;
            case UIGestureRecognizerStateCancelled:
            case UIGestureRecognizerStateFailed:
            case UIGestureRecognizerStateEnded: [fourWayArrowImageView removeFromSuperview]; break;
        }
    }
    

    So the scrolling in zoom mode now exactly works like photo app.

    Hope this helps

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

Sidebar

Related Questions

After quite a long time perusing the web i have decided to come here
Okay this may be a simple question but I have yet to come with
After fiddling around with an issue I am having I have come to this
I have come across html2canvas thanks to a previous question of mine. What I
Have been working on this question for a couple hours and have come close
,This question is likely subjective, but a lot of grid Javascript plugins have come
I have recently come across an interesting question on strings. Suppose you are given
I have come across this question: If process A contains a pointer to a
This question might be a bit long and specific, but I have been attempting
I'm trying to use Entity Framework for the first time, and have come a

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.