Javascript 卡布奇诺-CPSplitView固定子视图';大小
我有一个类Javascript 卡布奇诺-CPSplitView固定子视图';大小,javascript,objective-c,user-interface,cappuccino,objective-j,Javascript,Objective C,User Interface,Cappuccino,Objective J,我有一个类GridNode继承自CPSplitView,用于包装GridELement类型的对象。GridNode的每个连续拆分将其拆分为两个新的GridNode(包含与其父节点一起调整大小的GridElements) 另一个类-GridToolbar继承自GridElement。它应该基本上具有与GridElement相同的行为,尽管大小不应该自动改变(随着容器大小的调整),但只有在用户拖动拆分器之后 问题是,即使我将AutoresizingMask设置为特定方向(工具栏可以是垂直的,也可以是
GridNode
继承自CPSplitView
,用于包装GridELement
类型的对象。GridNode
的每个连续拆分将其拆分为两个新的GridNode
(包含与其父节点一起调整大小的GridElements
)
另一个类-GridToolbar
继承自GridElement
。它应该基本上具有与GridElement
相同的行为,尽管大小不应该自动改变(随着容器大小的调整),但只有在用户拖动拆分器之后
问题是,即使我将AutoresizingMask
设置为特定方向(工具栏可以是垂直的,也可以是水平的),它仍然会在这两个方向上调整大小
我能做些什么来防止这种情况发生,有什么建议吗
GridNode.j的来源:
@implementation GridNode : CPSplitView
{
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if(self)
{
[self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable ];
[self setBackgroundColor:[CPColor colorWithHexString:"EEEEEE"]]
}
return self;
}
- (void)split:(id)sender
{
var parent = [sender superview];
var gridNode = [
[GridNode alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
];
[gridNode setVertical:(CGRectGetWidth([gridNode bounds]) >= CGRectGetHeight([gridNode bounds]) ? YES : NO)]
var element = [
[GridElement alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
];
[self replaceSubview:parent with:gridNode];
[parent setBtnTarget:gridNode];
[element setBtnTarget:gridNode];
[gridNode addSubview:parent];
[gridNode addSubview:element];
}
- (void)addBar:(id)sender
{
var parent = [sender superview];
var gridNode = [
[GridNode alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
];
[gridNode setVertical:(CGRectGetWidth([gridNode bounds]) >= CGRectGetHeight([gridNode bounds]) ? YES : NO)]
var isVertical = [gridNode isVertical];
var toolbar = [
[GridToolbar alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
vertical: isVertical
];
[parent setBounds:CGRectMake(
isVertical ? 32 : 0, isVertical ? 0 : 32,
CGRectGetWidth([gridNode bounds]) - (isVertical ? 32 : 0),
CGRectGetHeight([parent bounds]) - (isVertical ? 0 : 32)
)];
[self replaceSubview:parent with:gridNode];
[parent setBtnTarget:gridNode];
[toolbar setBtnTarget:gridNode];
[gridNode addSubview:toolbar];
[gridNode addSubview:parent];
}
@end
@implementation GridElement : CPView
{
CPButton btnSPlit;
CPButton btnToolbar;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame]
if (self)
{
[self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable ];
[self setBackgroundColor:[CPColor colorWithCalibratedRed:Math.random() green:Math.random() blue:Math.random() alpha:1.0]];
btnSPlit = [
[CPButton alloc]
initWithFrame:CGRectMake(0,0,128,24)
];
[btnSPlit setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[btnSPlit setFrameOrigin:CGPointMake((CGRectGetWidth([self bounds]) - CGRectGetWidth([btnSPlit frame])) / 2.0,
(CGRectGetHeight([self bounds]) - CGRectGetHeight([btnSPlit frame])) / 2.0 - 15)];
[btnSPlit setTitle:"split me!"];
[btnSPlit setAction:@selector(split:)];
[self addSubview:btnSPlit]
btnToolbar = [
[CPButton alloc]
initWithFrame:CGRectMake(0,0,128,24)
];
[btnToolbar setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[btnToolbar setFrameOrigin:CGPointMake((CGRectGetWidth([self bounds]) - CGRectGetWidth([btnToolbar frame])) / 2.0,
(CGRectGetHeight([self bounds]) - CGRectGetHeight([btnToolbar frame])) / 2.0 + 15)];
[btnToolbar setTitle:"split me!"];
[btnToolbar setAction:@selector(addBar:)];
[self addSubview:btnToolbar]
}
return self;
}
- (void)setBtnTarget:(id)aTarget
{
[btnSPlit setTarget:aTarget];
[btnSPlit setTitle:"split "+aTarget._UID]
[btnToolbar setTarget:aTarget];
[btnToolbar setTitle:"toolbar "+aTarget._UID]
}
@end
@implementation GridToolbar : GridElement
{
CPButtonBar btnBar;
}
- (id)initWithFrame:(CGRect)aFrame vertical:(BOOL)isVertical
{
self = [super initWithFrame:CGRectMake(
0,0,
isVertical == NO ? aFrame.size.width : 32,
isVertical == YES ? aFrame.size.height : 32
)]
if(self)
{
isVertical == YES ? [self setAutoresizingMask:CPViewWidthSizable] : [self setAutoresizingMask:CPViewHeightSizable];
[self setBackgroundColor:[CPColor blackColor]];
btnBar = [
[CPButtonBar alloc]
initWithFrame:CGRectMake(
0,0,
CGRectGetWidth([self bounds]),
CGRectGetHeight([self bounds])
)
];
}
return self;
}
@end
GridElement.j的来源:
@implementation GridNode : CPSplitView
{
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if(self)
{
[self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable ];
[self setBackgroundColor:[CPColor colorWithHexString:"EEEEEE"]]
}
return self;
}
- (void)split:(id)sender
{
var parent = [sender superview];
var gridNode = [
[GridNode alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
];
[gridNode setVertical:(CGRectGetWidth([gridNode bounds]) >= CGRectGetHeight([gridNode bounds]) ? YES : NO)]
var element = [
[GridElement alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
];
[self replaceSubview:parent with:gridNode];
[parent setBtnTarget:gridNode];
[element setBtnTarget:gridNode];
[gridNode addSubview:parent];
[gridNode addSubview:element];
}
- (void)addBar:(id)sender
{
var parent = [sender superview];
var gridNode = [
[GridNode alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
];
[gridNode setVertical:(CGRectGetWidth([gridNode bounds]) >= CGRectGetHeight([gridNode bounds]) ? YES : NO)]
var isVertical = [gridNode isVertical];
var toolbar = [
[GridToolbar alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
vertical: isVertical
];
[parent setBounds:CGRectMake(
isVertical ? 32 : 0, isVertical ? 0 : 32,
CGRectGetWidth([gridNode bounds]) - (isVertical ? 32 : 0),
CGRectGetHeight([parent bounds]) - (isVertical ? 0 : 32)
)];
[self replaceSubview:parent with:gridNode];
[parent setBtnTarget:gridNode];
[toolbar setBtnTarget:gridNode];
[gridNode addSubview:toolbar];
[gridNode addSubview:parent];
}
@end
@implementation GridElement : CPView
{
CPButton btnSPlit;
CPButton btnToolbar;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame]
if (self)
{
[self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable ];
[self setBackgroundColor:[CPColor colorWithCalibratedRed:Math.random() green:Math.random() blue:Math.random() alpha:1.0]];
btnSPlit = [
[CPButton alloc]
initWithFrame:CGRectMake(0,0,128,24)
];
[btnSPlit setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[btnSPlit setFrameOrigin:CGPointMake((CGRectGetWidth([self bounds]) - CGRectGetWidth([btnSPlit frame])) / 2.0,
(CGRectGetHeight([self bounds]) - CGRectGetHeight([btnSPlit frame])) / 2.0 - 15)];
[btnSPlit setTitle:"split me!"];
[btnSPlit setAction:@selector(split:)];
[self addSubview:btnSPlit]
btnToolbar = [
[CPButton alloc]
initWithFrame:CGRectMake(0,0,128,24)
];
[btnToolbar setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[btnToolbar setFrameOrigin:CGPointMake((CGRectGetWidth([self bounds]) - CGRectGetWidth([btnToolbar frame])) / 2.0,
(CGRectGetHeight([self bounds]) - CGRectGetHeight([btnToolbar frame])) / 2.0 + 15)];
[btnToolbar setTitle:"split me!"];
[btnToolbar setAction:@selector(addBar:)];
[self addSubview:btnToolbar]
}
return self;
}
- (void)setBtnTarget:(id)aTarget
{
[btnSPlit setTarget:aTarget];
[btnSPlit setTitle:"split "+aTarget._UID]
[btnToolbar setTarget:aTarget];
[btnToolbar setTitle:"toolbar "+aTarget._UID]
}
@end
@implementation GridToolbar : GridElement
{
CPButtonBar btnBar;
}
- (id)initWithFrame:(CGRect)aFrame vertical:(BOOL)isVertical
{
self = [super initWithFrame:CGRectMake(
0,0,
isVertical == NO ? aFrame.size.width : 32,
isVertical == YES ? aFrame.size.height : 32
)]
if(self)
{
isVertical == YES ? [self setAutoresizingMask:CPViewWidthSizable] : [self setAutoresizingMask:CPViewHeightSizable];
[self setBackgroundColor:[CPColor blackColor]];
btnBar = [
[CPButtonBar alloc]
initWithFrame:CGRectMake(
0,0,
CGRectGetWidth([self bounds]),
CGRectGetHeight([self bounds])
)
];
}
return self;
}
@end
GridToolbar.j的来源
@implementation GridNode : CPSplitView
{
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if(self)
{
[self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable ];
[self setBackgroundColor:[CPColor colorWithHexString:"EEEEEE"]]
}
return self;
}
- (void)split:(id)sender
{
var parent = [sender superview];
var gridNode = [
[GridNode alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
];
[gridNode setVertical:(CGRectGetWidth([gridNode bounds]) >= CGRectGetHeight([gridNode bounds]) ? YES : NO)]
var element = [
[GridElement alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
];
[self replaceSubview:parent with:gridNode];
[parent setBtnTarget:gridNode];
[element setBtnTarget:gridNode];
[gridNode addSubview:parent];
[gridNode addSubview:element];
}
- (void)addBar:(id)sender
{
var parent = [sender superview];
var gridNode = [
[GridNode alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
];
[gridNode setVertical:(CGRectGetWidth([gridNode bounds]) >= CGRectGetHeight([gridNode bounds]) ? YES : NO)]
var isVertical = [gridNode isVertical];
var toolbar = [
[GridToolbar alloc]
initWithFrame:CGRectMake(
0, 0,
CGRectGetWidth([parent bounds]),
CGRectGetHeight([parent bounds])
)
vertical: isVertical
];
[parent setBounds:CGRectMake(
isVertical ? 32 : 0, isVertical ? 0 : 32,
CGRectGetWidth([gridNode bounds]) - (isVertical ? 32 : 0),
CGRectGetHeight([parent bounds]) - (isVertical ? 0 : 32)
)];
[self replaceSubview:parent with:gridNode];
[parent setBtnTarget:gridNode];
[toolbar setBtnTarget:gridNode];
[gridNode addSubview:toolbar];
[gridNode addSubview:parent];
}
@end
@implementation GridElement : CPView
{
CPButton btnSPlit;
CPButton btnToolbar;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame]
if (self)
{
[self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable ];
[self setBackgroundColor:[CPColor colorWithCalibratedRed:Math.random() green:Math.random() blue:Math.random() alpha:1.0]];
btnSPlit = [
[CPButton alloc]
initWithFrame:CGRectMake(0,0,128,24)
];
[btnSPlit setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[btnSPlit setFrameOrigin:CGPointMake((CGRectGetWidth([self bounds]) - CGRectGetWidth([btnSPlit frame])) / 2.0,
(CGRectGetHeight([self bounds]) - CGRectGetHeight([btnSPlit frame])) / 2.0 - 15)];
[btnSPlit setTitle:"split me!"];
[btnSPlit setAction:@selector(split:)];
[self addSubview:btnSPlit]
btnToolbar = [
[CPButton alloc]
initWithFrame:CGRectMake(0,0,128,24)
];
[btnToolbar setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[btnToolbar setFrameOrigin:CGPointMake((CGRectGetWidth([self bounds]) - CGRectGetWidth([btnToolbar frame])) / 2.0,
(CGRectGetHeight([self bounds]) - CGRectGetHeight([btnToolbar frame])) / 2.0 + 15)];
[btnToolbar setTitle:"split me!"];
[btnToolbar setAction:@selector(addBar:)];
[self addSubview:btnToolbar]
}
return self;
}
- (void)setBtnTarget:(id)aTarget
{
[btnSPlit setTarget:aTarget];
[btnSPlit setTitle:"split "+aTarget._UID]
[btnToolbar setTarget:aTarget];
[btnToolbar setTitle:"toolbar "+aTarget._UID]
}
@end
@implementation GridToolbar : GridElement
{
CPButtonBar btnBar;
}
- (id)initWithFrame:(CGRect)aFrame vertical:(BOOL)isVertical
{
self = [super initWithFrame:CGRectMake(
0,0,
isVertical == NO ? aFrame.size.width : 32,
isVertical == YES ? aFrame.size.height : 32
)]
if(self)
{
isVertical == YES ? [self setAutoresizingMask:CPViewWidthSizable] : [self setAutoresizingMask:CPViewHeightSizable];
[self setBackgroundColor:[CPColor blackColor]];
btnBar = [
[CPButtonBar alloc]
initWithFrame:CGRectMake(
0,0,
CGRectGetWidth([self bounds]),
CGRectGetHeight([self bounds])
)
];
}
return self;
}
@end
我收到了一个有用的建议。我只需要创建自己的代理,在拖动分隔符的同时,根据固定的值集自动调整
GridNode
子视图的大小。今天的一些屏幕截图,也许用几个箭头来显示它应该是什么样子会使理解和帮助更快。实际上我收到了一个有用的建议。我所要做的就是创建自己的代理,在拖动调整器的同时,根据设置的固定值自动调整GridNode
子视图的大小。