autosize如何在iPhone SDK中运行?

时间:2010-06-05 17:38:05

标签: iphone objective-c ipad uiview

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

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

我需要做很多自定义的事情,所以我将所有内容都包含在内。

alt text http://img248.imageshack.us/img248/4201/49422483.png

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

----更新:

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

我的问题是如何构建我的代码,尤其是关于定位和自动调整的代码,以实现您在图片#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时,一切都运行正常。

1 个答案:

答案 0 :(得分:1)

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

相关问题