Re: resizeWithOldSuperviewSize not getting called on added Subview


Dave
 

This is a Mac Project.

I’ve not found anything obvious on this, so I’m trying to get to the bottom of why the auto-resizing mechanism is not working with Class that inherits from NSImageView called GameImageView. An object is created and added to the view hierarchy at run time.

The view hierarchy is actually setup in a Storyboard/NIB and looks something like this:

WindowTrackerView
GameBaseView
TopAreaView
BottomAreaView
LeftAreaView
RightAreaView
GameBoardView
GameClusterView1
GameCellView1
GameCellView2
GameCellViewN
GameClusterView2
GameCellView1
GameCellView2
GameCellViewN
GameClusterViewN
GameCellView1
GameCellView2
GameCellViewN


I am adding GameImageView to each of the GameCellView's at runtime. All the Views are now using resizeWithOldSuperviewSize to resize themselves and it works wonderfully EXCEPT then this mechanism is not working on the run-time added GameImageView’s, e.g. GameImageView ::resizeWithOldSuperviewSize never gets called, although it does get called in the GameCellView’s.

If I do this in the GameCellView:: resizeWithOldSuperviewSize method it works ok (e.g. the Image resized when I resize the window):

myCellStartPosition = [self getCellXYPosition];

myBoundingRect = self.superview.bounds;
myFrameRect = [self calculateFrameRectWithSuperViewRect:myBoundingRect];

myFrameRect.origin.x = (int) (3 + (myCellStartPosition.x * (myFrameRect.size.width + 2)));
myFrameRect.origin.y = (int) (3 + (myCellStartPosition.y * (myFrameRect.size.height + 2)));

self.frame = myFrameRect;

//**
//** Setup the Image View Frame based on the Cell’s view *********************
//**
myImageFrameRect = NSInsetRect(self.bounds,2,2);
self.pCellImageView.frame = myImageFrameRect;

e.g. if I set the the frame of the GameImageView in the Superclass it works ok. If I don’t do this expecting GameCellView:: resizeWithOldSuperviewSize to be called then the image does NOT resize, since it isn’t called!! I’m trying to understand why this doesn’t work as expected, I’m not doing anything different (apart from adding it as a subview at runtime) from the other classes in the hierarchy and they all work wonderfully.

I’ve more or less got it working, but this last part is driving me nuts, so if anyone can shed some light on what could be going wrong I’m be really grateful.

Thanks in advance.

All the Best
Dave

On 27 Sep 2018, at 20:10, Dave <dave@looktowindward.com> wrote:

Hi,

I’m using Manual Layout on a Mac project. The View Hierarchy is built in Interface Builder and during run time I add a subview to one of the views. However, resizeWithOldSuperviewSize is not being called on these subviews. The subview in question is a subclass of NSImageView.

I’ve explicitly set autoresizesSubviews = YES in the view that adds the subview (actually is all the views in the Hierarchy).

Anyone have half an idea why resizeWithOldSuperviewSize is not being called? The frame of the parent rectangle is definitely being set…..

All the Best
Dave






Join cocoa@apple-dev.groups.io to automatically receive all group messages.