【问题标题】:UIViewController.view.superview custom shapeUIViewController.view.superview 自定义形状
【发布时间】:2015-04-12 12:17:54
【问题描述】:

我有一个控制器在 iPad 上显示为自定义形状。实际上我已经使视图本身透明,但它的子视图对用户是可见的。 我在 viewWillLayoutSubviews 方法中使用以下代码来制作一个具有小矩形形式的控制器:

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

但是如果我不想要一个矩形怎么办?有没有办法不为此目的而令人兴奋的 CGPath?

【问题讨论】:

    标签: objective-c uiviewcontroller cgpath


    【解决方案1】:

    在这种情况下,您必须使用您想要的形状创建一个 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;
    

    【讨论】:

      猜你喜欢
      • 2017-03-05
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多