嵌套 UIView 调整大小
我正在开发我的第一个 iPad 应用程序,该应用程序是一个分割视图,就像邮件应用程序一样。在详细视图中,我有 2 个子视图,一个用于编辑数据,另一个用于仅查看数据。当用户处于视图模式时,他们按下按钮,详细视图就会翻转以显示编辑视图。
我似乎无法使详细视图中的两个视图随着 iPad 方向的变化而正确调整大小。在纵向模式下,视图的大小是正确的,但是当更改为横向模式时,两个子视图会在底部和右侧边缘处剪辑。我认为这些视图应该根据它们嵌套在其中的视图自动调整大小。
在根视图控制器中,我有以下代码:
@implementation RootViewController
@synthesize detailViewController;
@synthesize recipies= recipies;
@synthesize delegate;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
self.detailViewController.recipeView.autoresizingMask= (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth );
self.detailViewController.isEdit= FALSE;
self.detailViewController.editView.autoresizingMask= (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth );
self.detailViewController.editView.hidden= YES;
}
应该调整大小的子视图是recipeView 和editView。我认为通过设置 autoresizeingMask,它们会自动调整大小。我在这里缺少什么,我是否需要根据方向变化时的可用空间显式设置每个视图的大小?
任何/所有回复表示赞赏!提前致谢。
I'm developing my first iPad application, and the app is a split view like the mail app. Inside the detail view I have 2 sub views, one for editing data and one for just viewing data. When the user is in the view mode they press a button and the detail view flips over to reveal the edit view.
I can't seem to make the two views inside the detail view resize properly with the iPad orientation change. The views are the correct size when in portrait mode, but when changed to landscape mode, the two subviews clip at the bottom and right hand edges. I thought these views were supposed to resize automatically with the view they are nested inside.
In the root view controller, I have the following code:
@implementation RootViewController
@synthesize detailViewController;
@synthesize recipies= recipies;
@synthesize delegate;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
self.detailViewController.recipeView.autoresizingMask= (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth );
self.detailViewController.isEdit= FALSE;
self.detailViewController.editView.autoresizingMask= (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth );
self.detailViewController.editView.hidden= YES;
}
The subviews that should resize are recipeView and editView. I thought by setting the autoresizeingMask, they would automatically resize. What am I missing here, do I need to explicitly set the size of each view based on the available space on orientation change?
Any/All replies appreciated! Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您找到问题的答案了吗?我和你的处境相似或完全相同。我有一个详细视图,然后将索引 0 处的子视图插入到详细视图中,但大小都是错误的,我无法找出原因。
如果我同时添加详细视图和子视图(即将详细视图添加到 splitviewcontrollers 视图数组中),则大小是正确的,但如果我简单地将子视图插入到已经存在的详细视图中,则大小可以在纵向和不是横向或反之亦然(即我认为自动调整大小不起作用)。我的解决方案是在启动要插入的视图后,我检查方向并强制其大小。例如,
我的尺寸显然特定于我在下面的详细视图上拥有的工具栏或选项卡栏,这就是为什么我有奇怪的尺寸。
以我对 iOS sdk 的有限看法和理解,我上面的解决方案充其量只是一个 hack,iOS 应该为我们做这件事,而且一定有什么地方我们做错了。
Did you ever find an answer to your question. I am in a similar or exact same position as you. I have a the detailview and then insert subviews at index 0 onto the detailview but the sizes are all wrong and I cannot work out why.
If I add the detailview and a subview at the same time (ie add the detailview to the splitviewcontrollers array of views) then the sizes are correct, but if i simple insert a subview onto the already existing detailview then the size either works in Portrait and not in landscape or vica versa (ie I think the autoresize does not work). My solution is after initiating a view to be inserted I check orientation and force its size. eg
My sizings are obviously specific to what toolbars or tabbars I have on the detailview underneath which is why I have the strange sizes.
In my limited opinion and understanding of iOS sdk my solution above is a hack at best, iOS should be doing this for us and there must be something we are doing wrong.