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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:43:54+00:00 2026-05-22T18:43:54+00:00

I created a custom subclass of NSView in order to control 2 NSImageViews. The

  • 0

I created a custom subclass of NSView in order to control 2 NSImageViews. The code for creating the images is as follows:

- (id)initWithFrame:(NSRect)frameRect AndMap:(NSImage *)map AndPlayer:(NSImage *)guyImage
{
    self = [super initWithFrame:frameRect];
    if (self)
    {
        NSRect newRect = NSMakeRect(0.0, 0.0, 64.0, 64.0);

        NSImageView *theMap = [[NSImageView alloc] initWithFrame:NSMakeRect(0.0, 0.0, frameRect.size.width, frameRect.size.height)];
        [theMap setImage:map];

        NSImageView *theGuy = [[NSImageView alloc] initWithFrame:newRect];
        [theGuy setImage:guyImage];

        [self setMapImage:theMap];
        [self setPlayerView:theGuy];
        [self addSubview:[self mapImage]];
        [self addSubview:[self playerView]];

However, when I tell the view to draw in a rect with origin (128,0), it draws theMap with a weird offsets, so that theGuy‘s origin is at 128,0, but theMap‘s origin is at something like (128,20). I can’t find any reason why this should occur.

  • 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-22T18:43:55+00:00Added an answer on May 22, 2026 at 6:43 pm

    My guess is that you have overlapping sibling views:

    • theMap has frame {{0.0, 0.0}, {frameRect.size.width, frameRect.size.height}}
    • theGuy has frame {{0.0, 0.0}, {64.0, 64.0}}
    • both theMap and theGuy are (or seem to be) added to the same superview, namely self, and have the same origin.

    Cocoa doesn’t guarantee correct behaviour for overlapping sibling views, i.e., two views that have the same direct superview and whose corresponding frames overlap. From the View Programming Guide:

    Note: For performance reasons, Cocoa does not enforce clipping among sibling views or guarantee correct invalidation and drawing behavior when sibling views overlap. If you want a view to be drawn in front of another view, you should make the front view a subview (or descendant) of the rear view.

    According to this answer to another question on Stack Overflow, one alternative solution is to turn on layers for the views.

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

Sidebar

Related Questions

Here's the scenario - I have created a custom NSView subclass, and the implementation
In my Cocoa Application I have created a Custom View Class (subclass of NSView),
I created my own subclass of UINavigationBar in order to enable custom background that
I have created a custom subclass of UITableViewCell. There, I allow the user to
I created a custom UITableViewCell subclass which contains a button named testbtn . I
I have created a subclass of UITableViewController that is used as the custom class
I created custom adapter for listview which contain text and images, on click of
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a custom UIButton (UIButton subclass) for my application. Within this button's
I have a custom NSView subclass that I want to animate with Core Animation.

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.