4

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

在此处输入图像描述

对了,看到底部 40px 的黑色空间了吗?

我正在通过执行以下操作来创建红色视图:

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

然后我用那个框架创建视图。

但是,一旦我尝试在红色视图上添加自动调整大小的蒙版,它就会失去底部 40 像素,并且只会填满整个视图。对于那些不熟悉的人TwUI,自动调整大小掩码示例如下所示:

view.autoresizingMask = TUIViewAutoresizingFlexibleHeight;

因此,自动调整大小的遮罩采用了 iOS 对应的遮罩。但是,设置该掩码会这样做:

在此处输入图像描述

所以我的问题是,我怎样才能在这个视图的底部保留一个边距?

4

1 回答 1

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];
}
于 2011-07-11T11:15:48.767 回答