gpt4 book ai didi

ios - 如何模仿 iOS 邮件应用程序在旋转期间的自动布局变化?

转载 作者:行者123 更新时间:2023-11-29 02:30:16 25 4
gpt4 key购买 nike

我想模仿 iOS 邮件应用程序的行为,左 Pane 使用表格 View 筛选邮件,右 Pane 预览邮件以便于阅读。

我注意到在横向模式下,存在左侧带有邮件项目的表格 View 。但当用户切换到纵向模式时,左侧 Pane 完全消失,右侧的阅读 Pane 会平滑扩展以占用额外的空间。

当用户恢复到横向模式时,左 Pane 再次出现,一切恢复正常。

我正在尝试用下面的代码做同样的事情:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{

UIToolbar *toolbar = self.toolbar;
UITableView *tableView = self.tableView;
UIWebView *webView = self.webView;

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
[self.toolbar setHidden:YES];
[self.tableView setHidden:YES];

[self.view removeConstraint:self.equalWidthsToolbarWebviewConstraint];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[webView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(webView)]];
} else if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
[self.toolbar setHidden:NO];
[self.tableView setHidden:NO];



//TODO: Set up views to have equal widths
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[toolbar][webView(==toolbar)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(toolbar,webView)]];

}
}

当我将 iPad 从横向设置为纵向模式时,左 Pane View 消失,右 Pane 最终展开。但是,当我将其恢复为横向时,左右 Pane 不会恢复到它们曾经的布局。

这是我在调试器中得到的:

2014-11-17 15:16:02.721 Citta Streams iOS[2366:17353693] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7c971df0 UITableView:0x7c1b8800.leading == UIToolbar:0x7c976f90.leading>",
"<NSLayoutConstraint:0x7c971e50 H:|-(0)-[UITableView:0x7c1b8800] (Names: '|':UIView:0x7c971780 )>",
"<NSLayoutConstraint:0x7c971eb0 H:[UIWebView:0x7c9f91a0]-(0)-| (Names: '|':UIView:0x7c971780 )>",
"<NSLayoutConstraint:0x7caa58f0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7c971780(768)]>",
"<NSLayoutConstraint:0x7c9e06b0 UIWebView:0x7c9f91a0.leading == UIView:0x7c971780.leadingMargin>",
"<NSLayoutConstraint:0x7b6c41a0 H:[UIToolbar:0x7c976f90]-(0)-[UIWebView:0x7c9f91a0]>",
"<NSLayoutConstraint:0x7b6c6150 UIWebView:0x7c9f91a0.width == UIToolbar:0x7c976f90.width>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7b6c41a0 H:[UIToolbar:0x7c976f90]-(0)-[UIWebView:0x7c9f91a0]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

最佳答案

不要浪费时间使用标准 UI 组件来复制此功能 - 苹果已将此功能内置到 UISplitViewController 中:

https://developer.apple.com/library/ios/documentation/uikit/reference/uisplitviewcontroller_class/index.html

关于ios - 如何模仿 iOS 邮件应用程序在旋转期间的自动布局变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26981204/

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