繁体   English   中英

屏幕方向更改时,UI贝塞尔曲线路径会更改LineWidth。

[英]UI Bezier Path changes LineWidth when screen orientation changes.

因此,我试图在自定义UIView中创建一组简单的轴。 这是代码:

@IBDesignable
class GraphingView: UIView {


@IBInspectable
var axesColor : UIColor = UIColor.redColor() { didSet{ setNeedsDisplay() } }

@IBInspectable
var lineWidth : CGFloat = 1.0 { didSet{ setNeedsDisplay() } }

var origin : CGPoint{
    return convertPoint(center, fromView: superview)
}


override func drawRect(rect: CGRect) {

    let axesPath = UIBezierPath()
    axesPath.moveToPoint(CGPoint(x: 0, y: origin.y))
    axesPath.addLineToPoint(CGPoint(x: bounds.width, y: origin.y))
    axesPath.moveToPoint(CGPoint(x: origin.x, y: 0))
    axesPath.addLineToPoint(CGPoint(x: origin.x, y: bounds.height))
    axesPath.lineWidth = lineWidth
    axesColor.set()
    axesPath.stroke()

}


}

纵向显示,这很好:

肖像

但在风景中,垂直线稍粗:

景观

谁能帮助我解决为什么发生这种情况以及如何解决呢? 谢谢!

我终于弄清楚了。 现在,自定义视图的模式设置为“缩放至填充”。 我只需要将其更改为“ redraw”,即可再次运行drawRect。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM