弄清楚TwUI中的自动调整掩码 - 底部边距?

时间:2011-07-09 20:25:39

标签: objective-c cocoa-touch cocoa macos twui

我在使用自动调整遮罩方面遇到了一些麻烦。这是交易:我正在使用最近发布的TwUI,它从UIKit获得了很多,但它在Mac上。这就是我为iOS和iPad标记的原因。苹果电脑。所以,我创建了一个视图,底部需要有40px的边距,无论窗口的垂直大小有多大。出于多种原因,我不允许窗口水平扩展。这是我正在谈论的样本的样子。抱歉丑陋的外表,我只是使用示例视图进行测试。

enter image description here

右,所以看到底部40px的黑色空间?

我正在通过这样的方式创建红色视图:

CGRect b = self.view.bounds;
b.origin.y += TAB_HEIGHT; //40px
b.size.height -= TAB_HEIGHT;

然后我用该框架创建视图。

然而,一旦我尝试在红色视图上添加自动调整大小的掩码,它就会失去40px的底部,并且只会填满整个视图。对于那些不熟悉TwUI的人来说,样本自动调整掩码如下所示:

view.autoresizingMask = TUIViewAutoresizingFlexibleHeight;

因此,自动调整面具采用iOS对应物。但是,设置该掩码会执行此操作:

enter image description here

所以我的问题是,如何在这个视图的底部保留一个余量?

1 个答案:

答案 0 :(得分:1)

@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];
}