0
我有一個叫做myView
的UIView
子類和一個叫做myViewController
的UIViewController
。UIView在iOS 10屏蔽
我將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一切非常好。
不適用於我...任何其他想法? –
嗯,我正在解決我的問題大約一個小時,我的理解是現在你應該非常小心'self.bounds'' self.frame'等原因在我的情況下我操縱UIView'掩碼時,其框架,這在2.3中很好,變成了(0,0,1000,1000),所以我通過打印'UIView.bounds'來修復它,將它放在不同的函數中,並最終找到了一種方法來使它不是(0 ,0,1000,1000)(通過添加'self.view.layoutSubviews()')。我的猜測是你的問題是相似的,但我不是100%確定的。 – JuicyFruit
'self.bounds':(0.0,0.0,375.0,113.5) 'self.frame':=(0.0,553.5,375.0,113.5) –