2011-07-09 20 views
4

我在自动修复蒙版时遇到了一些麻烦。这是一笔交易:我使用最近发布的TwUI,这需要从UIKit购买很多,但它在Mac上。这就是为什么我标记为两个iOS的& Mac。所以,我创建了一个视图,无论窗口的垂直尺寸有多大,都需要底部有40px的边距。我不允许横向扩展窗口,原因有很多。这是一个样本,看起来像我在说什么。对于丑陋的外观很抱歉,我只是使用示例视图来测试。找出TwUI中的自动调整掩码 - 底部边距?

enter image description here

权豪,所以看到的黑色空间底部的40像素?

我做这样的事情创建红色视图:

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

这很可能是一个错误(当然看起来像它给我)。 TwUI是全新的,所以它可能值得报告。 –

回答

1

@Rob,我没有麻烦自动调整它。

以下代码是我用Twui github主干修改了一个空项目的代码。

- (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]; 
} 
+0

我忘了在'TUIViewController'中初始化这个视图。对于普通的'TUIView',它似乎可以正常工作,但是使用'TUIViewController'弄糟了它,因为视图在viewDidLoad期间没有最终边界。 –

+0

你可以粘贴你的视图控制器的'-loadView'吗? – ZhangChn

+0

当然! http://pastebin.com/pYEccTRr –