OStack程序员社区-中国程序员成长平台

标题: ios - 圆形 View 和颜色以及带有动画的 cifilter [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 20:01
标题: ios - 圆形 View 和颜色以及带有动画的 cifilter

我正在开发一个应用程序,我需要在用户单击 UIButton 时制作效果。

http://imageshack.com/a/img802/3337/on55.png

当用户单击屏幕截图中心的按钮时,图片上会出现一个带有颜色的光环,该光环正在通过网络请求加载。图片加载了颜色,实际上我在其上应用了一个去除颜色的 cifilter。

如果可能,请向我解释如何使用背景图像重现圆形 View 。

谢谢。



Best Answer-推荐答案


所以,我试图解释我的解决方案,我是法国人,我的英语很差

为了实现这一点,我使用自定义 drawrect 制作了一个 uiview,PaintCode 确实帮助我做到了这一点,因为我的设计师制作了一些 svg 示例文件,我将它加载到 PaintCode 中以制作 UIBezierPath。像这样。

UIBezierPath* bezier2Path = [UIBezierPath bezierPath];
    [bezier2Path moveToPoint: CGPointMake(160, 228.1)];
    [bezier2Path addCurveToPoint: CGPointMake(148.16, 239.5) controlPoint1: CGPointMake(153.46, 228.1) controlPoint2: CGPointMake(148.16, 233.2)];
    [bezier2Path addCurveToPoint: CGPointMake(160, 250.9) controlPoint1: CGPointMake(148.16, 245.8) controlPoint2: CGPointMake(153.46, 250.9)];
    [bezier2Path addCurveToPoint: CGPointMake(171.84, 239.5) controlPoint1: CGPointMake(166.54, 250.9) controlPoint2: CGPointMake(171.84, 245.8)];
    [bezier2Path addCurveToPoint: CGPointMake(160, 228.1) controlPoint1: CGPointMake(171.84, 233.2) controlPoint2: CGPointMake(166.54, 228.1)];
    [bezier2Path closePath];
    [bezier2Path moveToPoint: CGPointMake(160, 249.51)];
    [bezier2Path addCurveToPoint: CGPointMake(149.62, 239.5) controlPoint1: CGPointMake(154.26, 249.51) controlPoint2: CGPointMake(149.62, 245.03)];
    [bezier2Path addCurveToPoint: CGPointMake(160, 229.49) controlPoint1: CGPointMake(149.62, 233.97) controlPoint2: CGPointMake(154.26, 229.49)];
    [bezier2Path addCurveToPoint: CGPointMake(170.38, 239.5) controlPoint1: CGPointMake(165.74, 229.49) controlPoint2: CGPointMake(170.38, 233.97)];
    [bezier2Path addCurveToPoint: CGPointMake(160, 249.51) controlPoint1: CGPointMake(170.38, 245.03) controlPoint2: CGPointMake(165.74, 249.51)];
    [bezier2Path closePath];
    bezier2Path.miterLimit = 4;

当 uiview 初始化时,我在使用 AFNetworking 从 Internet 下载我的图像时初始化她。我在drawrect中的 View 背景中设置图像,如下所示:

//// General Declarations
CGContextRef context = UIGraphicsGetCurrentContext();


//// Image Declarations
UIImage* bGTest = [UIImage imageNamed:self.image];

//// Calque_2_-_copie
{
    //// Bezier 2 Drawing
    UIBezierPath* bezier2Path = [UIBezierPath bezierPath];
    [bezier2Path moveToPoint: CGPointMake(160, 228.1)];
    [bezier2Path addCurveToPoint: CGPointMake(148.16, 239.5) controlPoint1: CGPointMake(153.46, 228.1) controlPoint2: CGPointMake(148.16, 233.2)];
    [bezier2Path addCurveToPoint: CGPointMake(160, 250.9) controlPoint1: CGPointMake(148.16, 245.8) controlPoint2: CGPointMake(153.46, 250.9)];
    [bezier2Path addCurveToPoint: CGPointMake(171.84, 239.5) controlPoint1: CGPointMake(166.54, 250.9) controlPoint2: CGPointMake(171.84, 245.8)];
    [bezier2Path addCurveToPoint: CGPointMake(160, 228.1) controlPoint1: CGPointMake(171.84, 233.2) controlPoint2: CGPointMake(166.54, 228.1)];
    [bezier2Path closePath];
    [bezier2Path moveToPoint: CGPointMake(160, 249.51)];
    [bezier2Path addCurveToPoint: CGPointMake(149.62, 239.5) controlPoint1: CGPointMake(154.26, 249.51) controlPoint2: CGPointMake(149.62, 245.03)];
    [bezier2Path addCurveToPoint: CGPointMake(160, 229.49) controlPoint1: CGPointMake(149.62, 233.97) controlPoint2: CGPointMake(154.26, 229.49)];
    [bezier2Path addCurveToPoint: CGPointMake(170.38, 239.5) controlPoint1: CGPointMake(165.74, 229.49) controlPoint2: CGPointMake(170.38, 233.97)];
    [bezier2Path addCurveToPoint: CGPointMake(160, 249.51) controlPoint1: CGPointMake(170.38, 245.03) controlPoint2: CGPointMake(165.74, 249.51)];
    [bezier2Path closePath];
    bezier2Path.miterLimit = 4;

    CGContextSaveGState(context);
    [bezier2Path addClip];
    [bGTest drawInRect: CGRectMake(0, 0, bGTest.size.width, bGTest.size.height)];
    CGContextRestoreGState(context);
}

这真的很简单,之后我可以只使用 alpha 组件为我的 View 设置动画来制作我的波纹动画。

现在看截图:

http://imageshack.com/a/img839/4613/v2wm.png

感谢您的回复。

关于ios - 圆形 View 和颜色以及带有动画的 cifilter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22354324/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4