自动调整大小如何在iPhone SDK中运行? [英] How does autosize work in iPhone SDK?

查看:117
本文介绍了自动调整大小如何在iPhone SDK中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下操作:

I'm trying to do the following:

alt text http://img101.imageshack.us/img101/7396/33959221.png

我需要做一个很多自定义的东西,所以我将所有东西都分类。

I need to do a lot of custom things, so I subclassed everything.

替代文字http://img248.imageshack.us/img248/4201/49422483.png

我遇到了自动调整大小的问题和定位。例如,UIToolBar位置不正确。
所以这是一个问题:
如果你不使用UITableViewController或任何其他控制器,它负责所有的定位和大小调整,那么你必须自己做。
有人可以告诉我这是如何工作的吗?我需要了解什么?

I'm having issues with autoresize and positioning. For instance the UIToolBar is not at the correct position. So here is the question: If you don't use UITableViewController or any other Controller, that takes care of all the positioning and sizing, then you have to do it yourself. Can someone someone tell me how this works? What do I need to understand?

----更新:

我的自定义目标实际上并不那么重要,因为我的问题实际上是关于别的东西。但是没问题。因此,像TableView,工具栏和TabBar这样的所有元素都将具有自定义背景并使用自定义按钮。 TableView将是GroupedStyle并且可以折叠组。

My custom goals are actually not that important as my question is actually about something else. But OK. So all "elements" like the TableView, the Toolbar and the TabBar will have custom backgrounds and use custom buttons. The TableView will be GroupedStyle and the groups can be collapsed.

我的问题是我如何构建我的代码,特别是关于定位和自动调整以实现你能做到的参见图片#1。

My question is how do I have to structure my code especially regarding positioning and autoresizing in order to achieve what you can see in picture #1.

这就是它现在的结构:

Application Delegate:
- (void) loadView {
  RootViewController *rootView = [[RootViewController alloc] init];
  [window addSubview:rootView.view];
  [window makeKeyAndVisible];

RootViewController:
- (void) loadView {
  self.theView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  self.theView.autoresizesSubviews = YES;
  self.theView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
  self.view = self.theView;

  ChildViewController *childView = [[ChildViewController alloc] init];

  [self.view addSubview:childView.view];

ChildViewController:
- (void) loadView {
  self.theView = [[UIView alloc] init];
  self.view = self.theView;
}
- (void) viewDidLoad {
  self.view.frame = [[UIScreen mainScreen] bounds];
  CGRect toolbarBounds = self.theToolbar.bounds;
  CGRect viewBounds = self.view.bounds;
  CGRect tableViewBounds = CGRectMake(0, CGRectGetHeight(toolbarBounds), CGRectGetWidth(viewBounds), CGRectGetHeight(viewBounds) - CGRectGetHeight(toolbarBounds));

  self.view.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

  self.theTableView = [[MyTableView alloc] initWithFrame:tableViewBounds 
                                                  style:UITableViewStyleGrouped 
                                                 parent:self];


  [self.view addSubview:self.theToolbar];
  [self.view addSubview:self.theTableView];
}

MyToolBar:
- (id)initWithParent:(id)theParent {
  if ((self = [self init])) {    
    self.parent = theParent;

    CGRect rectArea = CGRectMake(0, 0, CGRectGetWidth([[[self parent] view] bounds]), 44);
    [self setFrame:rectArea];

    self.autoresizingMask = UIViewAutoresizingFlexibleWidth;

    [self loadButtons];
  }
  return self;
}

所以这就是目前定位的结构(凌乱)。它确实有效,但是我有一个由ChildViewController处理的ModalView。当我在纵向视图中使用iPad并弹出模态视图并将其关闭时,一切正常。但是当我在Landscape视图中执行相同操作时,它会在解除模态视图时将孔视图... ChildViewController旋转90度。很奇怪。当我在AppDelegate中直接加载ChildViewController时,一切都运行正常。

So this is how the positioning is structured at the moment (messy). It actually works, BUT I have a ModalView which is handled by the ChildViewController. When I have the iPad in Portrait view and I pop up the modal view and dismiss it, then everything works. But when I do the same on Landscape view it rotates the hole view... the ChildViewController by 90 degrees when dismissing the modal view. Very strange. When I load directly ChildViewController in my AppDelegate, then again everything works fine.

推荐答案

您在自动调整中缺少UIViewAutoresizingFlexibleBottomMargin选项例如,工具栏的掩码。

You're missing the UIViewAutoresizingFlexibleBottomMargin option in the autoresize mask of your toolbar, for instance.

这篇关于自动调整大小如何在iPhone SDK中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆