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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:35:25+00:00 2026-05-27T09:35:25+00:00

I’ve got a scroller within my view and got several images inside this scroller.

  • 0

I’ve got a scroller within my view and got several images inside this scroller.

I’d like to drag and drop these images out (and into) my scroller. I implemented a LongPressGestureRecognizer.

I also would like to know (by code) which image got longpressed. I thought I fixed this last one by using CGRectContainsPoint. However my code is not reacting to the CGRectContainsPoint. It still Logs “fail”.

- (void)viewDidLoad{

    //scroller properties
    scroller.contentSize = CGSizeMake(1300, 130);
    scroller.scrollEnabled = YES;
    scroller.directionalLockEnabled =YES;
    scroller.frame = CGRectMake(0, 874, 768, 130);

    UILongPressGestureRecognizer *longPress =
    [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];

    [image1 addGestureRecognizer:longPress];
    [image2 addGestureRecognizer:longPress];
    [image3 addGestureRecognizer:longPress];
    [longPress release];

}

-(void)longPressed:(UILongPressGestureRecognizer *)sender {


    CGPoint location = [sender locationInView:self.view];

    if(CGRectContainsPoint(image1.frame,  location)) {
        NSLog(@"image1 has been longpressed");
        // do something
    }

    if(CGRectContainsPoint(image2.frame,  location)) {
        NSLog(@"image2 has been longpressed");
        // do something
    }

    if(CGRectContainsPoint(image3.frame,  location)) {
        NSLog(@"image3 has been longpressed");
        // do something


    }

         else {
                 NSLog(@"fail");
}

Has someone got experience with this LongPressGestureRecognizer and the number of images that can respond to this function?


i did succeeded implementing the two gesturerecognizers. So the images within my scroller are now draggable. However it limits itself inside the scrollview. I’d like to have some function which takes care of bringing the images in front of the scrollview, so that I can drag my images out of my scrollview.

Within my viewDidLoad method I implemented

[scroller addSubview:image1];
[scroller addSubview:image2];
[scroller addSubview:image3];

[[self view] addSubview:scroller];

and within my longPressed method I implemented

[image1 bringSubviewToFront:self.view];

Someone has good Tips? They are greatly appreciated!

  • 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-27T09:35:26+00:00Added an answer on May 27, 2026 at 9:35 am

    Add a scrollview and create one IBOutlet

    Add three images to your project in this answer i use the names
    image1.png, image2.png and image3.png

    And finally here is the code

    - (void) viewDidLoad{
            [super viewDidLoad];
    
            for (int i=1; i<=3; i++) {
                NSString *file = [NSString stringWithFormat:@"image%d.png", i];
                UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:file]];
                imageView.frame = CGRectMake(i * 200, 0, 200, 200);
                imageView.userInteractionEnabled = YES;
                imageView.tag = i;
                          
                UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer              alloc] initWithTarget:self action:@selector(longPress:)];
               
                [thumbView addGestureRecognizer:recognizer];
                [scrollView addSubview:thumbView];
            }
        }    
    
    -(void)longPress: (UILongPressGestureRecognizer *)recognizer
    {
            UIView *view  = recognizer.view;
            int index = view.tag;
            NSLog(@"image pressed : %i", índex);
    }
    

    With this approach you will be able to create 3 imageViews and add to them a gesture recognizer with less code and tell you wich imageView was longPressed

    But if you want to drag the imageView UILongPressGestureRecognizer is not going to work for you, for that task you should use UIPanGestureRecognizer

    If you want to drag the imageView out of the scrollView you can mimic that effect
    Removing/hiding the imageView from scrollView and add a imageView with the same image
    exactly where was the imageView you hide/remove into the view you want to drag the imageView

    Is more a visual effect but works

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.