如何为 iphone os 4.2 实现 splitview? [英] How implement splitview for iphone os 4.2?
问题描述
我在我的应用程序中使用了自定义拆分视图.
I have use the custom splitview in the my application.
自定义拆分视图 .h 文件
custom splitview .h file
@interface CustomUISplitViewController :UISplitViewController {
BOOL keepMasterInPortraitMode;
BOOL keepMasterInPortraitMode1;
}
.m 文件是
-(void) viewWillAppear:(BOOL)animated {
keepMasterInPortraitMode1=keepMasterInPortraitMode;
if(keepMasterInPortraitMode1 == NO) {
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
UIViewController* master = [self.viewControllers objectAtIndex:0];
UIViewController* detail = [self.viewControllers objectAtIndex:1];
[self setupPortraitMode:master detail:detail];
}
}
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
UIViewController* master = [self.viewControllers objectAtIndex:0];
UIViewController* detail = [self.viewControllers objectAtIndex:1];
[self setupPortraitMode:master detail:detail];
}
}
}
- (void)setupPortraitMode:(UIViewController*)master detail:(UIViewController*)detail {
//adjust master view
CGRect f = master.view.frame;
f.size.width = 220;
f.size.height = 1024;
f.origin.x = 0;
f.origin.y =0;
[master.view setFrame:f];
//adjust detail view
f = detail.view.frame;
f.size.width = 548;
f.size.height = 1024;
f.origin.x = 221;
f.origin.y = 0;
[detail.view setFrame:f];
}
这在 iOS4.0 下可以正常工作,但在 4.2 下,当应用程序运行时我只看到一个视图.操作系统版本之间会发生什么变化?
This works correctly under iOS4.0 but under 4.2 I see only one view when the app runs. What could change between OS versions?
推荐答案
我的应用程序也遇到了完全相同的问题.我使用了相同的子类化技术,让 Master 和 Detail 在纵向和横向模式下都可见.在 4.2 之前运行良好,遗憾的是我没有测试 Beta 版本何时可用.
I have had the exact same problem with my applications. I had used the same Subclassing technique to have the Master and Detail visible in both Portrait and Landscape modes. Worked great until 4.2 which, unfortunately I didn't test for when the Beta releases were available.
我建议尝试优秀的 MGSplitViewController (http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad).它是 UISplitViewController 的开源实现.唯一的缺点是在 Interface Builder 中使用起来不太容易,但它包含一个示例项目.在视觉上它与 UISplitViewController 相同,但增加了对一些附加功能的支持,例如在运行时拖动拆分位置.
I recommend trying the excellent MGSplitViewController (http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad). It is an open-source implementation of the UISplitViewController. It's only drawback is that it isn't quite as easy to use in Interface Builder, but it includes a sample project. Visually it is identical to UISplitViewController, but adds support for several extras such as dragging the split position at runtime.
只需完全按照您的 UISplitViewController 实现它,但在某处添加以下行:
Just implement it exactly as your UISplitViewController but add the following line somewhere:
[splitViewController setShowsMasterInPortrait:YES];
这与 Apple 禁止在其版本中使用的私有 API 非常相似.
This is very similar to the Private API that Apple prohibits using with their version.
//[splitViewController setHidesMasterViewInPortrait:NO]; // Naughty, Naughty, Not allowed by the Apple police
这篇关于如何为 iphone os 4.2 实现 splitview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!