【发布时间】:2017-02-11 14:25:22
【问题描述】:
我有一个名为myView 的UIView 子类和一个名为myViewController 的UIViewController。
我将myView 添加为myViewController 中的子类,并且我还在其文件中屏蔽myView 子视图。
问题是当我屏蔽时,视图完全消失了。
有人知道为什么吗?
谢谢!
我的代码:
myViewController:
override func viewDidLoad() {
let theView = myView(frame: CGRectZero)
theView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(theView)
theView.bottomAnchor.constraintEqualToAnchor(self.view.bottomAnchor).active = true
theView.leftAnchor.constraintEqualToAnchor(self.view.leftAnchor).active = true
theView.rightAnchor.constraintEqualToAnchor(self.view.rightAnchor).active = true
theView.heightAnchor.constraintEqualToAnchor(self.view.heightAnchor, multiplier: 0.17).active = true
}
myView:
override func layoutSubviews() {
super.layoutSubviews()
let ev = UIView(frame: self.bounds)
ev.backgroundColor = UIColor.blueColor()
ev.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(ev)
ev.rightAnchor.constraintEqualToAnchor(self.rightAnchor).active = true
ev.bottomAnchor.constraintEqualToAnchor(self.bottomAnchor).active = true
ev.leftAnchor.constraintEqualToAnchor(self.leftAnchor).active = true
ev.heightAnchor.constraintEqualToAnchor(self.heightAnchor, multiplier: 1.5).active = true
let myPath: CGPathRef = PocketSVG.pathFromSVGFileNamed("CategoriesBar").takeUnretainedValue() //Creating a CGPath object using a 3rd party API
var transform: CGAffineTransform = CGAffineTransformMakeScale(self.frame.size.width / 754.0, self.frame.size.height / 220.0) //Resizing it
let transformedPath: CGPathRef = CGPathCreateMutableCopyByTransformingPath(myPath, &transform)! //Creating a re-sized CGPath
let myShapeLayer = CAShapeLayer()
myShapeLayer.path = transformedPath
myShapeLayer.fillRule = kCAFillRuleEvenOdd
let myMaskedView = UIView(frame: self.frame)
myMaskedView.backgroundColor = UIColor.blackColor()
myMaskedView.layer.mask = myShapeLayer
ev.maskView = myMaskedView //THE PROBLEM. If I remove this line the view is visible (but it isn’t masked), but when I don’t the view just completely disappears!
}
注意:问题发生在我更新到 iOS 10 时,在 iOS 9 上一切正常。
【问题讨论】:
标签: ios iphone swift cocoa-touch uiview