autosize在iPhone SDK中是如何工作的?
我正在努力做到以下几点: 我需要做很多自定义的事情,所以我把所有的事情都子类化了 我在自动调整大小和定位方面有问题。例如,UIToolBar不在正确的位置。 问题是: 如果您不使用UITableViewController或任何其他控制器,这将负责所有的定位和大小调整,那么您必须自己进行。 有人能告诉我这是怎么回事吗?我需要了解什么 ----更新: 我的自定义目标实际上并不重要,因为我的问题实际上是关于其他事情的。但是好的。因此,所有“元素”如TableView、工具栏和选项卡栏都将具有自定义背景并使用自定义按钮。TableView将为GroupedStyle,并且可以折叠这些组 我的问题是,我必须如何构造我的代码,特别是关于定位和自动调整大小的代码,以实现您在图1中看到的效果 这就是它现在的结构:autosize在iPhone SDK中是如何工作的?,iphone,objective-c,ipad,uiview,Iphone,Objective C,Ipad,Uiview,我正在努力做到以下几点: 我需要做很多自定义的事情,所以我把所有的事情都子类化了 我在自动调整大小和定位方面有问题。例如,UIToolBar不在正确的位置。 问题是: 如果您不使用UITableViewController或任何其他控制器,这将负责所有的定位和大小调整,那么您必须自己进行。 有人能告诉我这是怎么回事吗?我需要了解什么 ----更新: 我的自定义目标实际上并不重要,因为我的问题实际上是关于其他事情的。但是好的。因此,所有“元素”如TableView、工具栏和选项卡栏都将具有自定
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设置为纵向视图时,我会弹出模态视图并将其关闭,然后一切正常。但当我在景观视图上做同样的操作时,它会旋转孔视图。。。解除模式视图时,将ChildViewController旋转90度。很奇怪。当我在AppDelegate中直接加载ChildViewController时,一切都正常。例如,您缺少工具栏自动调整大小掩码中的UIViewAutoresizingFlexibleBottomMargin选项。您需要列举一些自定义目标。在不知道任务的哪些方面真正需要自定义行为的情况下,建议一种方法是不可能的。您是在nib文件中定义工具栏还是以编程方式创建工具栏,技术将有所不同。