gpt4 book ai didi

uitableview - UISplitViewController 详细 View 不在旋转时调整大小

转载 作者:行者123 更新时间:2023-12-02 02:17:49 49 4
gpt4 key购买 nike

我希望我能正确描述这种情况。当它发生时很容易在屏幕上看到,但很难用语言解释,但我会尽力而为。

我有一个带有固定主视图 (UITableView) 和两个详细 View 之一的 UISplitViewController,具体取决于在主视图中触摸的单元格类型。每个详细信息 View 也是一个 UITableView。我使用 Todd Bates 将 Apple 的 MultipleDetailViews 示例转换为使用 Storyboard作为我的代码的基础 (Adventures in UISplitViewController)。

我正在使用 Storyboard,所以这就是解释部分变得棘手的地方。 Master 和第一个显示的 Detail view Navigation Controllers 在 Storyboard 中作为与 UISplitViewController 的关系连接起来。第二个 Detail Navigation Controller 只是坐在 Storyboard中,没有任何连接。

问题来了。细节 #1 在横向模式下处于事件状态,细节 #2 通过点击主视图中的一行设置为事件状态。 iPad 旋转到纵向模式,这会导致细节 #2 为纵向模式正确调整大小。通过轻敲母版中的一行将细节 #1 设置为事件状态。细节 #1 与上次在横向模式下显示时的大小相同,它没有按应有的方式填满屏幕。

我的问题是,我可以告诉当前未显示的 Detail Controller 在方向改变时自行调整大小吗?或者更好的问题是如何调整刚刚显示的详细 View 的大小以填充 UISplitView 的详细信息部分?

我希望我描述的足够详细,以便有人提供帮助。

UISplitViewControllerDelegate 方法在管理器类中实现,该类应该将这些调用转发给详细 View Controller 。下面是该方法的实现:

#pragma mark - UISplitViewControllerDelegate

/* forward the message to the current detail view
* all detail views must implement UISplitViewControllerDelegate
*/
-(void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
self.masterBarButtonItem = barButtonItem;
self.masterPopoverController = pc;

barButtonItem.title = NSLocalizedString(@"Games", @"Games");

[self.currentDetailController.navigationItem setLeftBarButtonItem:self.masterBarButtonItem animated:YES];
}

/* forward the message to the current detail view
* all detail views must implement UISplitViewControllerDelegate
*/
-(void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
self.masterBarButtonItem = nil;
self.masterPopoverController = nil;

[self.currentDetailController.navigationItem setLeftBarButtonItem:nil animated:YES];
}

并且我在每个细节 View Controller 中实现了以下内容:

#pragma mark - Split view

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = NSLocalizedString(@"Games", @"Games");
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
}

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}

问题是两个 Detail view controller 都没有接收到这些消息。我看不出它们是如何被触发的...

我看不出转发 didRotateFromInterfaceOrientation: 会如何导致未显示的 Detail Controller 调整自身大小。来自 Apple 的文档:

When the orientation of an iOS–based device changes, the system sends out a UIDeviceOrientationDidChangeNotification notification to let any interested parties know that the change occurred. By default, the UIKit framework intercepts this notification and uses it to update your interface orientation automatically. This means that, with only a few exceptions, you should not need to handle this notification at all. Instead, all you need to do is implement the appropriate methods in your view controller classes to respond to orientation changes.

The window object does much of the work associated with changing the current orientation. However, it works in conjunction with the root view controller to determine whether an orientation change should occur at all and, if so, what additional methods should be called to respond to the change. If this controller is a container, it may rely on a child to decide whether the orientation should occur.

When a rotation occurs, methods of the view controller are called at various stages of the rotation to give the view controller a chance to perform additional tasks. You might use these methods to hide or show views, reposition or resize views, or notify other parts of your app about the orientation change. Because your custom methods are called during the rotation operation, you should avoid performing any time-consuming operations there. You should also avoid replacing your entire view hierarchy with a new set of views. There are better ways to provide unique views for different orientations, such as presenting a new view controller (as described in “Creating an Alternate Landscape Interface”).

最佳答案

与 splitViewController 方法类似,您应该转发以下调用:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];

// Forward to detail view controller here:

}

到不可见的详细 View Controller (即不是 self.currentDetailController,而是另一个)。

关于uitableview - UISplitViewController 详细 View 不在旋转时调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9661904/

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