iphone - iPhone SDK 中的自动调整大小如何工作?

标签 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 或任何其他 Controller 来处理所有定位和大小调整,那么您必须自己完成。 有人可以告诉我这是如何工作的吗?我需要了解什么?

----更新:

我的自定义目标实际上并不那么重要,因为我的问题实际上是关于其他事情。但是没问题。因此,所有“元素”(例如 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 置于纵向 View 并弹出模态视图并将其关闭时,一切都会正常。但是,当我在横向 View 上执行相同操作时,它会在关闭模态视图时将孔 View 旋转... ChildViewController 90 度。很奇怪。当我在 AppDelegate 中直接加载 ChildViewController 时,一切都正常。

最佳答案

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

关于iphone - iPhone SDK 中的自动调整大小如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2981364/

相关文章:

iPhone背景音乐播放器

ios - 停止销售应用程序但上传升级

iOS 从服务器接收 udp 响应

c++ - xcode 4.5 中出现“iostream”文件未找到错误?

ios - 测试时我的 iPhone 上的应用程序启动缓慢

iphone - 对核心数据中实体之间的属性进行计算

iphone - 从 iPhone 向 Ruby on Rails (RoR) 服务器发送多部分请求

javascript - 在平板电脑上运行时将点击事件变成触摸事件

ios - 如何像Appstore一样在ipad中查看

iphone - 展开和折叠 UITableview