Как нарисовать эффект размытия по Гауссу?

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

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

введите здесь описание изображения

    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;

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

введите здесь описание изображения

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

Я обновил приведенный ниже код

- (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);
    }

}

введите здесь описание изображения

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

Спасибо.


person Nandhakumar    schedule 30.05.2019    source источник
comment
проверьте этот stackoverflow .com/questions/37745673/ может быть вам поможет, дайте мне знать   -  person Reinier Melian    schedule 30.05.2019
comment
у меня только вылет   -  person Nandhakumar    schedule 30.05.2019
comment
сбой или ошибка? этому коду было 2 года, я все равно могу его обновить, кстати, этот ответ был на Swift   -  person Reinier Melian    schedule 30.05.2019


Ответы (2)


Переводя мой предыдущий ответ с 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

Результат введите здесь описание изображения

person Reinier Melian    schedule 30.05.2019
comment
#reinier-melian Я добавил код, но я не получил точное положение размытия, пожалуйста, проверьте мой вопрос Я обновил новый код и снимок экрана - person Nandhakumar; 30.05.2019
comment
@Nandhakumar я проверю и дам тебе знать - person Reinier Melian; 31.05.2019

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

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

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

person BhargavR    schedule 30.05.2019