在UISplitViewController中更改Master的宽度 [英] Change the width of Master in UISplitViewController
本文介绍了在UISplitViewController中更改Master的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
iPad编程指南说splitView的左侧窗格固定为320点。但是我的主视图控制器的320像素太多了。我想减少它,并为详细视图控制器提供更多空间。无论如何都可以吗?
The iPad programming guide says that the splitView's left pane is fixed to 320 points. But 320 pixels for my master view controller is too much. I would like to reduce it and give more space to detail view controller. Is it possible by anyway?
链接到文件,说明固定宽度。
Link to the document which speaks about fixed width.
推荐答案
如果你是UISplitViewController的子类,你可以实现 -viewDidLayoutSubviews
并调整那里的宽度。这是干净的,没有黑客或私有API,甚至可以轮换使用。
If you subclass UISplitViewController, you can implement -viewDidLayoutSubviews
and adjust the width there. This is clean, no hacks or private APIs, and works even with rotation.
- (void)viewDidLayoutSubviews
{
const CGFloat kMasterViewWidth = 240.0;
UIViewController *masterViewController = [self.viewControllers objectAtIndex:0];
UIViewController *detailViewController = [self.viewControllers objectAtIndex:1];
if (detailViewController.view.frame.origin.x > 0.0) {
// Adjust the width of the master view
CGRect masterViewFrame = masterViewController.view.frame;
CGFloat deltaX = masterViewFrame.size.width - kMasterViewWidth;
masterViewFrame.size.width -= deltaX;
masterViewController.view.frame = masterViewFrame;
// Adjust the width of the detail view
CGRect detailViewFrame = detailViewController.view.frame;
detailViewFrame.origin.x -= deltaX;
detailViewFrame.size.width += deltaX;
detailViewController.view.frame = detailViewFrame;
[masterViewController.view setNeedsLayout];
[detailViewController.view setNeedsLayout];
}
}
这篇关于在UISplitViewController中更改Master的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文