2011-07-09 34 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 –