내가 가지고 CGPath
내가 PocketSVG
API를 사용하여 SVG
파일에서 만들 수 있습니다. 그것은 모두 잘 작동합니다.
문제점
문제는 모양이 어떤 이유로 뻗어 있다는 것입니다, 청색은 그것을 무시하세요, 그것은해야 만 할 것입니다 당신에게 더 볼 수 있습니다 (이 그림에서 봐 주시기 바랍니다 수 ClearColor
) :
는 내가 달성하고자하는 않는 대상? 나는 화면의 너비에 걸쳐가는 모양을 얻고 싶다. (나는 높이를 신경 쓰지 않고 너비에 맞게 수정해야한다.) 그리고 화면 하단에 붙어있다.이 그림을 다음과 같이 보아라. 도 (원형 버튼을 무시하세요) :
강령
중요한 부분, 나는 SVG
파일에서이 모양을 그립니다 UIView
의 서브 클래스가
) 그것은 0을 불렀다.. 그런 다음 내 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 배 더 길기 때문입니다. 경로의 간단한 확장. –