简体   繁体   English

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

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

So I am trying to create a simple set of axes in a custom UIView. 因此,我试图在自定义UIView中创建一组简单的轴。 Here's the code: 这是代码:

@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()

}


}

In portrait, this turns out fine: 纵向显示,这很好:

肖像

but in landscape, the vertical line is a little bit thicker: 但在风景中,垂直线稍粗:

景观

Can anyone help me with why that happens and how to fix it? 谁能帮助我解决为什么发生这种情况以及如何解决呢? Thanks! 谢谢!

I figured it out in the end. 我终于弄清楚了。 Right now, the mode for the custom view was set at "Scale to Fill". 现在,自定义视图的模式设置为“缩放至填充”。 I just had to change it to "redraw" so it would run drawRect again. 我只需要将其更改为“ redraw”,即可再次运行drawRect。

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

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