@Rob,我自动调整大小没有问题。
以下代码是我用 TwUI github trunk 修改了一个空项目。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
TUINSView *content = [[TUINSView alloc] initWithFrame:CGRectZero];
CGRect b = [window frame];
b.origin = CGPointZero;
content.frame = b;
[window setContentView:content];
TUIView *viewA = [[TUIView alloc] initWithFrame:CGRectZero];
viewA.frame = content.bounds;
viewA.backgroundColor = [TUIColor blackColor];
[content setRootView:viewA];
viewA.autoresizingMask = TUIViewAutoresizingFlexibleSize;
TUIView *viewB = [[TUIView alloc] initWithFrame:CGRectZero];
viewB.backgroundColor = [TUIColor redColor];
b = viewA.bounds;
b.origin.y+=30;
b.size.height-=30;
viewB.frame = b;
[viewA addSubview:viewB];
viewB.autoresizingMask = TUIViewAutoresizingFlexibleSize;
}
编辑:我像这样编写了我的 TUIViewController 的 loadView,它到目前为止运行良好。
- loadView {
TUIView *v = [[TUIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
tableView = [[TUITableView alloc] initWithFrame:v.bounds style:TUITableViewStylePlain];
[tableView scrollToTopAnimated:NO];
tableView.autoresizingMask = TUIViewAutoresizingFlexibleSize;
document = [[BBSDocDocument alloc] init];
tableView.delegate = self;
tableView.dataSource = self;
CGRect rect = [v bounds];
[v addSubview:tableView];
[self setView:v];
}
编辑 2:我的 TUIViewController 子类代码:
//TestVC.h:
#import <Foundation/Foundation.h>
#import "TUIKit.h"
@interface TestVC : TUIViewController {
@private
TUIView *viewA;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
@end
//TestVC.m
@implementation TestVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nil bundle:nil];
if (self) {
// Initialization code here.
}
return self;
}
- (void)loadView {
self.view = [[[TUIView alloc] initWithFrame:CGRectZero] autorelease];
self.view.autoresizingMask = TUIViewAutoresizingFlexibleSize;
}
//application delegate:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
TUINSView *content = [[TUINSView alloc] initWithFrame:CGRectZero];
CGRect b = [window frame];
b.origin = CGPointZero;
content.frame = b;
[window setContentView:content];
TUIView *viewA = [[TUIView alloc] initWithFrame:CGRectZero];
viewA.frame = content.bounds;
viewA.backgroundColor = [TUIColor blackColor];
[content setRootView:viewA];
[viewA setAutoresizingMask:TUIViewAutoresizingFlexibleSize];
TUIView *viewB = [[TUIView alloc] initWithFrame:CGRectZero];
viewB.backgroundColor = [TUIColor redColor];
b = viewA.bounds;
b.origin.y+=30;
b.size.height-=30;
viewB.frame = b;
[viewA addSubview:viewB];
viewB.autoresizingMask = TUIViewAutoresizingFlexibleSize;
TestVC *testVC = [[TestVC alloc] initWithNibName:nil bundle:nil];
testVC.view.frame = viewB.bounds;
testVC.view.backgroundColor = [TUIColor yellowColor];
[viewB addSubview:testVC.view];
}