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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:28:08+00:00 2026-06-01T09:28:08+00:00

How can I programmatically make an NSView so that the user can move its

  • 0

How can I programmatically make an NSView so that the user can move its position with the mouse? What properties do i need to assign to the view? thanks!

    newView = [helpWindow contentView];
    [contentView addSubview:newView];
    //add properties of newView to be able to respond to touch and can be draggable
  • 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-01T09:28:10+00:00Added an answer on June 1, 2026 at 9:28 am

    Unfortunately, there’s no simple way like setMoveByWindowBackground: that you can do with a window. You have to override mouseDown:, mouseDragged:, and mouseUp: and use setFrameOrigin: based on the position of the mouse pointer. In order not have the view jump when you first click inside it, you also need to account for the offset between the view’s origin and where the moue pointer is in the view when you first click. Here is an example that I made in a project to move “tiles” around in a parent view (this was for a computer version of the game “Upwords”, which is like 3d scrabble).

    -(void)mouseDown:(NSEvent *) theEvent{
        self.mouseLoc = [theEvent locationInWindow];
        self.movingTile = [self hitTest:self.mouseLoc]; //returns the object clicked on
        int tagID = self.movingTile.tag;
        if (tagID > 0 && tagID < 8) {
            [self.viewsList exchangeObjectAtIndex:[self.viewsList indexOfObject:self.movingTile] withObjectAtIndex: 20]; // 20 is the highest index in the array in this case
            [self setSubviews:self.viewsList]; //Reorder's the subviews so the picked up tile always appears on top
            self.hit = 1;
            NSPoint cLoc = [self.movingTile convertPoint:self.mouseLoc fromView:nil];
            NSPoint loc = NSMakePoint(self.mouseLoc.x - cLoc.x, self.mouseLoc.y - cLoc.y);
            [self.movingTile setFrameOrigin:loc];
            self.kX = cLoc.x;  //this is the x offset between where the mouse was clicked and "movingTile's" x origin
            self.kY = cLoc.y;  //this is the y offset between where the mouse was clicked and "movingTile's" y origin
        }
    }
    
    -(void)mouseDragged:(NSEvent *)theEvent {
        if (self.hit == 1) {
            self.mouseLoc = [theEvent locationInWindow];
            NSPoint newLoc = NSMakePoint(self.mouseLoc.x - self.kX, self.mouseLoc.y - self.kY);
            [self.movingTile setFrameOrigin:newLoc];
        }
    }
    

    This example points out one more possible complication. As you move a view around, it may appear to move underneath other views, so I take care of that my making the moving view the top most view of the parent view’s subviews (viewsList is the array gotten from self.subviews)

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

Sidebar

Related Questions

I want to programmatically make it so that users can see only particuar items
Is it possible to make it so that the user can click on an
How can I programmatically make this NSString : ( 548760 ) It's basically: (
How can I programmatically determine sites of a SharePoint 2007 installation that use custom
How can I programmatically get the phone number of the device that is running
Can I make an emergency call programmatically in Android 2.1? I've tried to use
How can I programmatically make a query in MS Access default to landscape when
Does anyone know if there any way that I can programmatically create a bean
How can I make a screenshot programmatically in iOS?
How can I make a phone call programmatically on iPhone? I tried the following

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.