Zi0P4tch0
Zi0P4tch0

Reputation: 63

How do you move a NSImageView?

I have this situation:

I have a NSView which contains a custom NSImageView. I'm trying to move the NSImageView from the view controller, but no success so far.

This is the header of the view controller:

#import <Cocoa/Cocoa.h>

#include "MyAppDragAndDropImageView.h"

@interface MyAppViewController : NSViewController <MyAppDragAndDropImageViewDelegate>

@property (nonatomic,assign) IBOutlet MyAppDragAndDropImageView *dragAndDropImageView;

@property (nonatomic,assign) IBOutlet NSTextField *workingFileLabel;
@property (nonatomic,assign) IBOutlet NSTextField *workingFileSizeLabel;

@property (nonatomic,assign) IBOutlet NSButton *clearButton;

-(IBAction)onClearButtonClicked:(id)sender;

All IBOutlets have been connected from the Interface Builder.

I'm using this code inside the view controller to move the custom NSImageView...

-(void)awakeFromNib
{
    //dragAndDropImageView frame
    NSRect ddivFrame = [dragAndDropImageView frame];
    ddivFrame.origin.x = SOME_NUMBER;
    ddivFrame.origin.y = SOME_NUMBER;

    [dragAndDropImageView setFrame:ddivFrame];
    [dragAndDropImageView setNeedsDisplay:YES];

}

...But nothing happens!

Using NSLog I've found that the frame "x" and "y" have been updated, but it is displayed in the old position! Any clues?

Thanks

Upvotes: 3

Views: 934

Answers (2)

Peter Hosey
Peter Hosey

Reputation: 96393

dragAndDropImageView and clearButton are centered inside the view. In awakeFromNib I set them offscreen, and then I use a NSAnimation to slide them in.

Why not set them as hidden/alphaValue to 0 in the nib, and then have your NSViewAnimation both show them (fade them in) and move them into position?

Upvotes: 0

Zi0P4tch0
Zi0P4tch0

Reputation: 63

I have found a solution:

-(void)awakeFromNib
{
    //dragAndDropImageView frame
    NSRect ddivFrame = [dragAndDropImageView frame];
    ddivFrame.origin.x = SOME_NUMBER;
    ddivFrame.origin.y = SOME_NUMBER;

    [[dragAndDropImageView animator] setFrame:ddivFrame];

}

This works flawlessy!

Upvotes: 1

Related Questions