gpt4 book ai didi

ios4 - 如何为 iphone os 4.2 实现 splitview?

转载 作者:行者123 更新时间:2023-11-28 17:47:49 25 4
gpt4 key购买 nike

我在我的应用程序中使用了自定义 Split View。

自定义splitview .h文件

@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 下,当应用程序运行时我只能看到一个 View 。操作系统版本之间会发生什么变化?

最佳答案

我遇到了同样的问题,我认为这是一个 Apple 错误(我在一个月前提交了它,但他们没有回应。)对我来说,特别是应用程序启动时空白的“详细信息” View 在方向 UIInterfaceOrientationLandscapeRight (3)。它看起来像这样:http://d.pr/cGcU .当我将两个 View Controller 之一(例如 RootViewController)限制为仅横向时,就会发生这种情况:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

有了这个,在详细 View 的初始化过程中会发生以下情况:

2010-11-15 20:17:47.792 MultipleDetailViews[96250:207] firstDetailViewController willAnimateRotationToInterfaceOrientation: 3 (landscape)
2010-11-15 20:17:47.792 MultipleDetailViews[96250:207] self.view.hidden is: 0
2010-11-15 20:17:47.799 MultipleDetailViews[96250:207] rotating...
2010-11-15 20:17:47.848 MultipleDetailViews[96250:207] firstDetailViewController didRotateFromInterfaceOrientation
2010-11-15 20:17:47.849 MultipleDetailViews[96250:207] self.view.hidden is: 1

由于某些原因,细节 View 在旋转到方向 3 期间会神秘地隐藏起来。直到 Apple 修复此错误(它不会在 3.2 中发生),我的解决方法目前是覆盖细节 View Controller 中的以下方法,重新- 旋转完成后显示 View :

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
self.view.hidden = NO;
}

编辑:如果您的详细 View 不是 splitViewController.view 的直接 subview (例如,您正在使用 UINavigationController),您需要在 UISplitViewController 的详细信息侧的最顶层 View 上设置 hidden:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
// Make sure you set splitViewController via an outlet or get it via your AppDelegate
for (UIView *splitViewChild in splitViewController.view.subviews)
splitViewChild.hidden = NO;
}

关于ios4 - 如何为 iphone os 4.2 实现 splitview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4417789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com