Как нарисовать эффект размытия по Гауссу? - PullRequest
1 голос
/ 30 мая 2019

Мне нужно нарисовать эффект размытия на UIView, используя Objective C.

Вот мой дизайн

enter image description here

    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle: UIBlurEffectStyleExtraLight];

    UIVisualEffectView *contentView = [[UIVisualEffectView alloc] initWithEffect: blurEffect];

    contentView.layer.cornerRadius = 18.0;

    contentView.layer.masksToBounds = YES;

    contentView.backgroundColor = [UIColor whiteColor];

    contentView.userInteractionEnabled = NO;

    contentView.layer.shadowRadius = 10;

    contentView.layer.shadowOpacity = 0.2f;

    contentView.layer.shadowColor = [UIColor whiteColor].CGColor;

    contentView.layer.shadowOffset =  CGSizeZero;

    [contentView setFrame: annotationFrame];

    [contentView setTranslatesAutoresizingMaskIntoConstraints: YES];

    self.contentView = contentView;

ниже скриншота был текущий вывод с использованием приведенного выше кода

enter image description here

Я пробовал вышеуказанный код., но я не получил точного эффекта размытия, пожалуйста, предложите мне нарисовать этот дизайн.

Я обновил код ниже

- (void)drawRect:(CGRect)rect {

    [super drawRect: rect]; //i doubt we need a super drarRect here…

    [self drawMarker: self.markerView fillColor: [UIColor whiteColor]];

    CGContextRef ctx = UIGraphicsGetCurrentContext();


    CGPathRef path = CGPathCreateWithRoundedRect(CGRectInset(rect,  self.frame.size.width/4,  self.frame.size.height/4), self.frame.size.width/8, self.frame.size.height/8, nil);

    CGContextSetFillColorWithColor(ctx,[UIColor slateColor].CGColor);

    CGContextSetShadowWithColor(ctx, CGSizeZero, self.frame.size.height/4,  [UIColor slateColor].CGColor);


    for ( int i = 0; i<=6; i++) {
        CGContextAddPath(ctx, path);
        CGContextFillPath(ctx);
    }

}

enter image description here

Мне нужен эффект размытия позади моего зрения, пожалуйста, посоветуйте мне это.

Спасибо.

Ответы [ 2 ]

1 голос
/ 30 мая 2019

Переводя мой предыдущий ответ с swift на Objective-C, мы имеем это

@implementation UICustomBackgroundButton


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    [super drawRect:rect];

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGPathRef path = CGPathCreateWithRoundedRect(CGRectInset(rect,  self.frame.size.width/4,  self.frame.size.height/4), self.frame.size.width/8, self.frame.size.height/8, nil);

    CGContextSetFillColorWithColor(ctx,[UIColor blueColor].CGColor);
    CGContextSetShadowWithColor(ctx, CGSizeZero, self.frame.size.height/4,  [UIColor blueColor].CGColor);


    for ( int i = 0; i<=6; i++) {
        CGContextAddPath(ctx, path);
        CGContextFillPath(ctx);
    }
}


@end

Результат enter image description here

0 голосов
/ 30 мая 2019

Проверьте ниже ссылку, которую я использовал для эффекта размытия:

https://dzone.com/articles/applying-gaussian-blur-to-uiviews-with-swift-proto

Это касается только эффекта размытия по Гауссу.

...