2016-10-03 38 views
0

我有一个叫做myViewUIView子类和一个叫做myViewControllerUIViewControllerUIView在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一切非常好。

回答

0

'self.view.layoutSubviews()'in'viewDidLoad()''implementation'UIView'working for me。它与iOS10中的viewcontroller生命周期更改有关。

+0

不适用于我...任何其他想法? –

+0

嗯,我正在解决我的问题大约一个小时,我的理解是现在你应该非常小心'self.bounds'' self.frame'等原因在我的情况下我操纵UIView'掩码时,其框架,这在2.3中很好,变成了(0,0,1000,1000),所以我通过打印'UIView.bounds'来修复它,将它放在不同的函数中,并最终找到了一种方法来使它不是(0 ,0,1000,1000)(通过添加'self.view.layoutSubviews()')。我的猜测是你的问题是相似的,但我不是100%确定的。 – JuicyFruit

+0

'self.bounds':(0.0,0.0,375.0,113.5) 'self.frame':=(0.0,553.5,375.0,113.5) –