我刚刚定义了一个自定义视图,并定义了一个drawRect()来在视图的中心绘制一个圆。见下面的代码。但是,当我运行它时,圆圈会移动到右边距。我在MAC OS 10.10.3 Yosemite上运行Xcode 6.3.1
@IBDesignable
class FaceView: UIView
{
override func drawRect(regionThatNeedsToBeDrawn: CGRect){
var rect = regionThatNeedsToBeDrawn
var faceCenter = convertPoint(center, fromView: superview)
var path = UIBezierPath(arcCenter: faceCenter, radius: CGFloat(50.0), startAngle: CGFloat(0), endAngle: CGFloat(2*M_PI), clockwise: true)
UIColor.redColor().setFill()
UIColor.blackColor().setStroke()
path.lineWidth = 3.0
path.fill()
path.stroke()
}
}