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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:36:40+00:00 2026-06-18T20:36:40+00:00

I have a screen containing: UIView A UIScrollView, which contains UIView B The UIScrollView

  • 0

I have a screen containing:

  • UIView A
  • UIScrollView, which contains UIView B

The UIScrollView overlaps with UIView A (up until about halfway through it), allowing me to “drag” UIView B and make it overlap it with UIView A. This is so that when I let go of it, UIView B bounces nicely back into its original position (I don’t want to be able to drag it all around the screen, just from its starting point onto UIView A)

Now, I’m trying to detect a collision when the UIViews overlap. However, none is ever detected. I am using convertRect:toView: to get coordinates on the same system, but from tracing UIView B’s coordinates in its touchesMoved I see that “dragging” (scrolling the UIScrollView, really) doesn’t affect its frame’s origin coordinates. They are the same in touchedBegan as they are every time touchedMoved fires.

I’m assuming this is because UIView B isn’t really moving anywhere, UIScrollView is, meaning that the UIView’s origin point is always the same, even if its absolute coordinates aren’t. Any suggestion on how to handle this?

  • 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-18T20:36:41+00:00Added an answer on June 18, 2026 at 8:36 pm

    There will be overlap when scrollView.frame.origin.x + viewB.frame.size.width + scrollView.contentOffset.x >= viewA.frame.origin.x

    After Edit:

    I couldn’t get the scroll view to work so I tried it another way that worked pretty well. Instead of a scroll view, I just used a rectangular view with a background color, and added the blue square to it. I gave the blue square a set width and height in IB, centered it in the long skinny view (in the y direction), and had one other constraint to the left side of that long view. The IBOutlet leftCon is connected to that constraint. I then used this code to drag it, and have it go back when I let go:

    #import "ViewController.h"
    #import <QuartzCore/QuartzCore.h>
    
    @interface ViewController ()
    @property (strong,nonatomic) UIPanGestureRecognizer *panner;
    @property (strong,nonatomic) IBOutlet NSLayoutConstraint *leftCon;
    @property (strong,nonatomic) CADisplayLink *displayLink;
    @end
    
    @implementation ViewController {
        IBOutlet UIView *blueSquare;
    }
    
    -(void)viewDidLoad {
        self.panner = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
        [blueSquare addGestureRecognizer:self.panner];
    }
    
    - (void)handlePanGesture:(UIPanGestureRecognizer *)sender {
        CGPoint translate = [sender translationInView:self.view];
        if (self.leftCon.constant <160)
            if (self.leftCon.constant > 100) NSLog(@"Bang! We have a collision");
            self.leftCon.constant = translate.x;
        if (sender.state == UIGestureRecognizerStateEnded){
            [self startDisplayLink];
        }
    }
    
    
    -(void)startDisplayLink {
        self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(bounceBack:)];
        [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    }
    
    - (void)stopDisplayLink {
        [self.displayLink invalidate];
        self.displayLink = nil;
    }
    
    
    -(void)bounceBack:(CADisplayLink *) link {
        self.leftCon.constant -= 12;
        if (self.leftCon.constant < 2) {
            [self stopDisplayLink];
            self.leftCon.constant = 2;
        }
    }
    

    The numbers in the translate code (160 and 100) were determined empirically by logging. The 160 number keeps it from going off the right edge of the long view, and the 100 number is where it starts to overlap the black box.

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

Sidebar

Related Questions

I have a UIViewController containing its UIView which occupies the available screen (inbetween the
I have a UIScrollView which contains a sub-UIView, insetView which is used to display
I'm sorry for the horrible title. Essentially, I have a containing div which contains
I have a UIView on the screen that contains a few labels. I am
I have search screen which has 10 fields and involves around 5 to 6
i have a screen contains just two components 1-textView 2-button the textView starts from
In my current Ipad app, I have a split screen view in which the
I have created 4 tabs containing 4 images at the screen bottom in BlackBerry
I have a map, containing many objects in an area sized 5000*5000. my screen
I have a UIScrollView with several UIViews containing a UIImageView and a UILabel in

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.