我有一个CGPath
我从SVG
文件中使用PocketSVG
API创建。它一切正常。
的问题
的问题是,形状绵延出于某种原因,请把这张图片上看看(蓝色是只是为了让对你更加明显,请忽略它,它应该是ClearColor
):
我想要什么来实现呢?我想要实现一个遍布屏幕宽度的形状(我不关心高度,它应该根据宽度自行修改),并粘贴到屏幕的底部,请看看这张图片为阱(请忽略圆形按钮):
守则
最重要的部分;)
我有UIView
一个子类,从SVG
文件绘制这种形状,它叫CategoriesBarView
。然后,在我的MainViewController
(UIViewController
的一个子类)上,我创建了CategoriesBarView
的一个对象,并以编程方式将其设置为子视图。
CategoriesBarView
:
class CategoriesBarView: UIView {
override func layoutSubviews() {
let myPath = PocketSVG.pathFromSVGFileNamed("CategoriesBar").takeUnretainedValue()
var transform = CGAffineTransformMakeScale(self.frame.size.width/750.0, self.frame.size.height/1334.0)
let transformedPath = CGPathCreateCopyByTransformingPath(myPath, &transform)
let myShapeLayer = CAShapeLayer()
myShapeLayer.path = transformedPath
let blur = UIBlurEffect(style: .Light)
let effectView = UIVisualEffectView(effect: blur)
effectView.frame.size = self.frame.size
effectView.frame.origin = CGPointMake(0, 0)
effectView.layer.mask = myShapeLayer
self.addSubview(effectView)
}
}
MainViewController
:
override func viewDidLoad() {
super.viewDidLoad()
let testHeight = UIScreen.mainScreen().bounds.size.height/6 // 1/6 of the screen’s height, that is the height in the target picture approximately, doesn’t it?
let categoriesBarView = CategoriesBarView(frame: CGRect(x: 0, y: UIScreen.mainScreen().bounds.size.height - testHeight , width: UIScreen.mainScreen().bounds.size.width, height: testHeight))
categoriesBarView.backgroundColor = UIColor.blueColor() // AS I said, it should be ClearColor
self.view.addSubview(categoriesBarView)
}
请问你们谁知道这里为什么形状拉伸这样的问题是什么?如果有人能帮助我,我会很感激。
非常感谢你:)
您是否试图根据屏幕分辨率缩放您的路径? –
@DipenPanchasara你是什么意思?我怎样才能做到这一点?我应该在代码中更改哪些内容?谢谢! –
比方说你画一条100x100的路径,并且你希望它在320x100上看起来相同,然后把你的路径的x点乘以3.2,因为它的新区域比你的实际路径多3.2倍。简单的缩放你的路径。 –