2015-04-12 339 views
0

我有一個控制器呈現在iPad上的自定義形狀。實際上,我已經使視圖本身變得透明,但其子視圖對用戶可見。 我用下面的代碼viewWillLayoutSubviews方法,使一個小矩形形式的控制器:UIViewController.view.superview自定義形狀

self.view.backgroundColor = [UIColor clearColor]; 
self.view.superView.backgroundColor = [UIColor clearColor]; 
self.view.superview.bounds =... 

但是,如果我想不是矩形什麼?有沒有一種方法可以讓CGPath爲此達到目的?

回答

0

在這種情況下,您必須創建具有所需形狀的CAShapeLayer,然後使用您創建的CAShapeLayer遮罩視圖的圖層。例如,帶圓圈視圖的視圖:

UIBezierPath *aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) 
                radius:75 
               startAngle:0 
                endAngle:M_PI * 2 
                clockwise:YES]; 


CAShapeLayer *lm = [[CAShapeLayer alloc] init]; 
lm.path = aPath.CGPath; 
self.view.layer.mask = lm;