Resize master and detail view controllers in a spl

2020-03-20 05:49发布

I'm working in Xcode 4.2 and am developing an app where I want the menu screen to use a Split View. Really, all I need the Split View Controller for is to split some of the menu options into a left pane and right pane. I want to be able to set custom sizes for the master and detail view controllers, but nothing seems to be working for me. I've tried updating the frame sizes for each view controller with code like:

[self.view setFrame:CGRectMake(0, 0, 768, 502)];

in the viewDidLoad functions, but that doesn't seem to affect anything.

Is there a way to set custom sizes for the master and detail view controllers of a split view controller without instantiating the view controllers in say the AppDelegate.m file? I want to be able to edit each of the view controllers in the storyboard as they are menu screens with a lot of buttons and such.

3条回答
我只想做你的唯一
2楼-- · 2020-03-20 06:34

Use MGSplitViewController. It offers similar API to UIViewController, but offering additional features, such as split position, which is what you need.

查看更多
神经病院院长
3楼-- · 2020-03-20 06:42

Edit: In iOS 8+, the relative widths can be changed by specifying the minimum/maximumPrimaryColumnWidth properties or the preferredPrimaryColumnFraction.

The below answer is still true for iOS < 8:


You can't change the sizes for a split view controller.

See here: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html

"The UISplitViewController class is a container view controller that manages two panes of information. The first pane has a fixed width of 320 points and a height that matches the visible window height. The second pane fills the remaining space."

查看更多
一纸荒年 Trace。
4楼-- · 2020-03-20 06:47
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex;
{

    return proposedMinimumPosition + 238;
}

- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex;
{
    return proposedMaximumPosition - 200;
}

before the above delegate method add [splitView addDelegate:self];

查看更多
登录 后发表回答