作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在自动调整蒙版大小方面遇到了一些问题。这是交易:我正在使用最近发布的 TwUI
,它从 UIKit 中获取了很多,但它在 Mac 上。这就是我为 iOS 和 Mac 标记的原因。因此,我创建了一个底部需要有 40px 边距的 View ,无论垂直调整窗口的大小有多大。出于多种原因,我不允许水平扩展窗口。这是我正在谈论的示例。抱歉外观丑陋,我只是使用示例 View 进行测试。
对了,看到底部 40 像素的黑色空间了吗?
我正在通过执行以下操作来创建红色 View :
CGRect b = self.view.bounds;
b.origin.y += TAB_HEIGHT; //40px
b.size.height -= TAB_HEIGHT;
然后我用那个框架创建 View 。
但是,一旦我尝试在红色 View 上添加自动调整大小蒙版,它就会失去底部 40 像素,并填满整个 View 。对于那些不熟悉 TwUI
的人,自动调整掩码示例如下所示:
view.autoresizingMask = TUIViewAutoresizingFlexibleHeight;
因此,自动调整大小蒙版采用了 iOS 对应的蒙版。但是,设置该掩码会执行以下操作:
所以我的问题是,如何在此 View 的底部留出边距?
最佳答案
@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];
}
关于objective-c - 弄清楚 TwUI 中的自动调整大小掩码 - 底部边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6637301/
我是一名优秀的程序员,十分优秀!