GTAE86
GTAE86

Reputation: 1846

OS X App - Cannot Resize App Window

I have an OS X app originally built using Xcode 4, now using Xcode 7. When "springs-and-struts" was superseded by constraints, I reworked the UI to use constraints. Simple enough, and seemed to work well.

Fast forward two years after first release, and for the second release I needed to add controls and increase the height of the main app view. Unfortunately, my test team is using smaller screens and cannot see the whole view. They need to resize vertically.

Problem - even though the resize controls box is checked, the window cannot be resized. The controls do not show at run time. I tried

I am thinking this issue has something to do with constraints.... Any ideas on how to get resize to work?

Edit: After playing with a new test app some, I am more certain the problem is due to constraints. I have a control where I have constrained leading and trailing space to superview and width - there went horizontal resize.

I really need to have a view where the user can resize the window, but scroll the content. However, in this case, the content is other controls. I think on iOS, I would use a UIScrollView. On OS X, I have tried a scroll view control and have tried embedding in a scroll view, and neither have the desired effect.

Upvotes: 1

Views: 1402

Answers (2)

YoonHo
YoonHo

Reputation: 1066

In my case, it happened in this way (Xcode 13.1).

I mistakenly added a view from IB outside of the window view hierarchy. The new view was added as a separated object (a top node in the interface builder file). I added the new view into the window by drag-n-drop.

I found the new view had different behaviours, for example, I couldn't set the top space constraint. With this view in the view hierarchy, I couldn't change the window size (content view size) at all.

I removed the view and added another in the view hierarchy, it worked as normal.

I think IB initialises the view differently if it is a separated object (top node of the interface builder file).

Upvotes: 0

Kaylin1025
Kaylin1025

Reputation: 11

I had the same issue and solved it by adding a view to be used as a "container" in the view controller.

Pin the top left corner of the "container view" to the view controller (leading space 0 and top space 0). Add equal width and height constraints on the "container view" to the view controller. Then move all your objects into the "container view" and add your object constraints on the "container view" not the view controller.

Upvotes: 1

Related Questions