开发者

Cocoa - Programmatically stretching an NSView vertically, moving everything after it down

I have three NSViews stacked on each other, and I want to be able to programmatically resize the middle one to stretch it vertically, moving the bottom one down by the same amount that the middle one stretches.

Here is an ASCII picture:

|--------------|
|      1       |
|-------------开发者_如何学运维-|

|--------------|
|      2       |
|--------------|

|--------------|
|      3       |
|--------------|

So basically I want to be able to stretch NSView 2 vertically so that the resulting picture would look like this:

|--------------|
|      1       |
|--------------|

|--------------|
|              |
|      2       |
|              |
|--------------|

|--------------|
|      3       |
|--------------|

What is the correct way to go about doing this? Thanks!


Edit: Here's a follow-up question...

How can I go from this:

|--------------|
|      1       |
|--------------|

|--------------|
|      2       |
|--------------|

|--------------|
|     2.5      |
|--------------|

|--------------|
|      3       |
|--------------|

To this:

|--------------|
|      1       |
|--------------|

|--------------|
|              |
|      2       |
|              |
|--------------|

|--------------|
|              |
|     2.5      |
|              |
|--------------|

|--------------|
|      3       |
|--------------|


The easiest way to do this is with autoresizing mask.

You can set the autoresizing mask programatically with

- (void)setAutoresizingMask:(NSUInteger)mask

Or in Interface builder.

In IB, the first view's autorisizing mask would be

Cocoa - Programmatically stretching an NSView vertically, moving everything after it down

The second :

Cocoa - Programmatically stretching an NSView vertically, moving everything after it down

The third :

Cocoa - Programmatically stretching an NSView vertically, moving everything after it down


Sounds like you either need an NSSplitView or CHLayoutManager.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜