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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:37:12+00:00 2026-05-23T21:37:12+00:00

I have several views inside one main view. Those views are all behind one

  • 0

I have several views inside one main view. Those views are all behind one another so that only the top one is currently seen. What I would like to do is, upon some particular user input, have one of the views in the back move lower on the screen, so it can be seen below the top view. I’ve been trying to do it by determining if the two views are currently overlapping, lower the one in back, if they are still overlapping, lower it more, and so on until they no longer overlap and are both entirely visible. Then I’d like for the main view to resize so that both views can be seen but I think that’d just be using setBounds or setFrame, haven’t gotten there yet.

For the first problem I haven’t found a way to literally see if two views overlap, if that can’t be done I thought maybe by drawing rects on the view bounds and checking if those overlap, but I don’t get how I can do either of these. I think bounds or frame is needed, but I’m not really sure how these are different.

Basically, I want to check if two NSViews overlap, if they do, I want to lower one of them.

EDIT: This part of the problem is pretty much solved, but now a new problem arose. I have three views, one main view, and two subviews. The main view doesn’t have anything, it only contains several subviews, whatever is inside the main view is what should be seen. The two subviews are stacked on top of the main view, so that the frontmost one is the visible one, the one behind it is set to hidden. When the user hits start, the view in the back becomes visible and I set a repeating timer with a selector that will check if the views overlap, like @Vince said, if they do, it offset’s the one in the back down a little and checks again until they don’t overlap anymore. Using this:

- (void)updateViews {
CGRect viewFrame = [view frame]; //view is the frontmost view that will not move
CGRect backroundViewFrame = [backgroundView frame]; //the view in the back

CGRect rectIntersection = CGRectIntersection (viewFrame,
                                              backgroundFrame);

//if the intersect is NOT null, it'll offset down by 2
if (!CGRectIsNull(rectIntersection)) {
    CGRect newFrame = CGRectOffset (
                                    rectIntersection,
                                    0,     //doesn't move in x
                                    -2     //lowers by 2 in y
                                    );
    [backgroundView setFrame:newFrame]; //lowers the view to the new offset rect

} else{
    [viewsUpdater invalidate]; //stops the timer when rects no longer intersect
    viewsUpdater = nil;
}

The problem is that when I lower the backgroundView, it’s only visible in the space where it intersects with the front view. Even if I expand the main view lower (which is the idea, they will all start one on top of the other with the same dimensions and when the backgroundView lowers, the main view will adjust and display both). But right now it doesn’t matter how large the main view is, the backgroundView is only visible in the area where it intersects with the front view. I think it’s moving to where it has to, but by the time it stops it’s completely invisible, so I can’t tell.

Thanks for the help.

  • 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-23T21:37:12+00:00Added an answer on May 23, 2026 at 9:37 pm

    Basically, you will be able to know if two NSView objects overlaps by getting the intersection of the two frame properties (CGRectIntersection()) and then testing for the result to be null using CGRectIsNull().
    Here is the doc for it.

    Now, about putting one view over another, it sounds like you need to use this method from NSView : -(void)setSubviews:(NSArray *)newSubviews;, which according to the documentation, lets you reorder the subviews.

    Or simply using -(void)replaceSubview:(NSView *)oldView with:(NSView *)newView;, that said, since the oldView will be released, be careful to retain a reference to it before.

    If you just attempted to move a view lower, you only have to change the origin of the reciever’s frame, for example :

    CGRect actualFrame = [aView frame];
    CGPoint framesOrigin = actualFrame.origin;
    CGRect newFrame = CGRectMake(framesOrigin.x,
                                 (framesOrigin.y)+50,
                                 actualFrame.width,
                                 actualFrame.height);
    [aView setFrame:newFrame];
    

    This will move aView lower, by changing the y coordinate of its frame’s origin.

    Finally, about the difference between bounds and frame properties, this post on SO Difference between view’s frame and view’s bound + iPhone, should answer your question 😉

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

Sidebar

Related Questions

I have a one form tag inside my Index.aspx view. Index.aspx contains several partial
I have a custom view that contains several views in itself. I've made it
I have several views that will be access inside modal boxes instead of actual
I currently have a list view which has several rows of data and I
I have several UIViews and UIImageViews that are loaded inside a UIScrollView. Each page,
I have several views that submit to the same controller's ActionResult and would like
Okay here's the situation. Net 4 WPF NO Silverlight. I have several Views that
I have two nib files, one that will open at startup and another that
Currently, I have an NSStatusItem that, when clicked, shows a custom view below it.
I have an application with a view containing several subviews. The subviews did not

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.