2016-10-03 16 views
0

UIViewサブクラスmyViewUIViewControllermyViewControllerというサブクラスがあります。iOS 10のUIViewマスキング

myViewControllerの中にサブクラスとしてmyViewを追加しています。そのファイル内にサブビューも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に更新したときに問題が9すべてがあるのiOS上で、起こりました完璧に良い。

答えて

0

'viewDidLoad()'に ''を実装してください。 iOS10のビューコントローラのライフサイクルの変更に関係します。

+0

私にとってはうまくいきません...他のアイデアはありますか? –

+0

さて、私は約1時間問題を修正していましたが、理解したところでは、 'self.bounds'' self.frame'などに注意する必要があります。私の場合、UIViewのマスクを操作していました(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) –