我有一個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倍。簡單的縮放你的路徑。 –