我有一个简单的UIComponent覆盖measure和updateDisplayList来绘制一条垂直线。我通过考虑笔划宽度来计算线的起点和终点。代码如下。我希望将界限打印为(x:0 y:0 w:1 h:300),但它打印(x:0 y:0 w:1 h:299),即高度为299而不是300.我错过了吗?
override protected function measure():void
{
super.measure();
measuredWidth = measuredMinWidth = 300;
measuredHeight = measuredMinHeight = 300;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var stroke:SolidColorStroke = new SolidColorStroke(0xd8d8d8, 1, 1);
var g:Graphics = graphics;
g.clear();
var bX:Number;
var bY:Number;
var tX:Number;
var tY:Number;
var bW:Number;
var bH:Number;
bX = stroke.weight * 0.5;
bY = stroke.weight * 0.5;
tX = stroke.weight * 0.5;
tY = unscaledHeight - 1 - stroke.weight * 0.5;
bW = unscaledWidth - stroke.weight;
bH = unscaledHeight - stroke.weight;
trace ("From (", bX, ",", bY, ") To (", tX, ",", tY, ")");
stroke.apply(g, null, null);
g.moveTo(bX, bY);
g.lineTo(tX, tY);
trace ("Bounds:", getBounds(this));
}
答案 0 :(得分:0)
为什么使用神奇的数字→-1
?您已将所有参数作为参数。更改tY
的计算:
tY = unscaledHeight - stroke.weight * 0.5;