如何配置UIVisualEffectView以获得类似于默认UIAlertController与类型操作表的效果

时间:2016-09-28 11:10:28

标签: ios objective-c uialertcontroller

我希望在我的自定义视图中获得像圆角一样的动作表之类的视觉效果。

containerView = [UIView new];
[containerView setBackgroundColor:[UIColor colorWithWhite:1 alpha:1]];
[self addSubview:containerView];

UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];    
[containerView addSubview:effectView];

我已将子视图添加到容器视图中,我像这样应用了半径。

-(void) addCornerRadius:(float) cornerRad isTopSide:(BOOL) isTopSide
 {
    cornerRadius = cornerRad;
    isTop = isTopSide;

    UIBezierPath *maskPath;
    UIRectCorner  *corner;
    if (isTopSide)
    {
         corner = (UIRectCornerTopLeft|UIRectCornerTopRight);
    }
    else
    {
       corner = (UIRectCornerBottomLeft|UIRectCornerBottomRight);
    }

         maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                 byRoundingCorners:corner
                                       cornerRadii:CGSizeMake(cornerRad, cornerRad)];

       CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
      maskLayer.frame = self.bounds;
      maskLayer.path = maskPath.CGPath;
     self.layer.mask = maskLayer;
}

但我在创造效果方面并不像UIAlertController创造的效果那么近。怎么做到这一点?

0 个答案:

没有答案