Re: resizeWithOldSuperviewSize not getting called on added Subview
This is a Mac Project.toggle quoted messageShow quoted text
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:
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
On 27 Sep 2018, at 20:10, Dave <email@example.com> wrote: