标签: cashapelayer

在左上角创建自定义圆角矩形按钮角?

我有一个自定义按钮,我想让它的左上角看起来像普通的圆形矩形.

我找到了使所有角落变圆的代码:

_myButton.layer.cornerRadius = 8;
_myButton.layer.borderWidth = 0.5;
_myButton.layer.borderColor = [UIColor grayColor].CGColor;
_myButton.clipsToBounds = YES;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如何修复代码以使其在左上角四舍五入?


编辑:

_myButton.layer.borderWidth = 2;
_myButton.layer.borderColor = [UIColor blackColor].CGColor;

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_myButton.bounds
                                                    byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                        cornerRadii:CGSizeMake(7.0, 7.0)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

maskLayer.frame = _myButton.bounds;
maskLayer.path = maskPath.CGPath;
_myButton.layer.mask = maskLayer;
[maskLayer release];
Run Code Online (Sandbox Code Playgroud)

此代码不起作用.整个按钮消失.

cocoa-touch objective-c cashapelayer ios

11
推荐指数
1
解决办法
1万
查看次数

CAShapeLayer的框架和界限

我在工作CAShapeLayer.而企图拉拢非线性path.I要设置框架CAShapeLayer.所以我可以使用CGPathGetPathBoundingBox的方法从得到的帧CGPathRef.

这是代码:

CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100, (0), (M_PI_2), NO);
CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100-50, (M_PI_2), (0), YES);
CGPathCloseSubpath(path);
CAShapeLayer* arcLayer = [[CAShapeLayer alloc]init];
arcLayer.path = path;
arcLayer.frame = CGPathGetPathBoundingBox(path);
arcLayer.bounds = CGPathGetPathBoundingBox(path);
[self.layer addSublayer:arcLayer]; ` 
Run Code Online (Sandbox Code Playgroud)

请参考我的代码仔细.我已设置相同的框架和范围,以CAShapeLayer.My问题是,如果我没有设置界限(同帧),那么它不会显示我的内容或它不会显示内frame.Why我的内容?请帮助我.谢谢你.

cashapelayer cgpath ios

11
推荐指数
2
解决办法
1万
查看次数

如何在UIImageview中添加圆形蒙版并更改框架和中心?

我想为UIImageVIew添加一个圆形蒙版.这是用于添加掩码的函数..

- (void) addMaskToBounds:(CGRect) maskBounds
{
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

    CGPathRef maskPath = CGPathCreateWithEllipseInRect(maskBounds, NULL);
    maskLayer.bounds = maskBounds;
    [maskLayer setPath:maskPath];
    [maskLayer setFillColor:[[UIColor blackColor] CGColor]];
    maskLayer.position = CGPointMake(maskBounds.size.width/2, maskBounds.size.height/2);

    [self.imageView.layer setMask:maskLayer];
}
Run Code Online (Sandbox Code Playgroud)

能够添加掩码,但问题出现,因为我正在改变图像框架并与其一起居中.根据用户操作放大图像并缩小图像.因此,当小和扩大时,我将不得不添加两次.因此,由于动画帧的变化,动画图像变得扭曲或移位.我该如何克服这个问题?

我想最好用一个示例项目来解释.在这里,我在GitHub上创建了一个Demo项目https://github.com/akshaynhegde/MaskImage,只需运行它来查看我的问题,让我知道如何解决问题.

calayer uiimageview cashapelayer uiviewanimation ios

10
推荐指数
2
解决办法
1万
查看次数

动画绘制CAShapeLayer的填充

我一直在玩这个伟大的文章http://oleb.net/blog/2010/12/animating-drawing-of-cgpath-with-cashapelayer中描述的使用CAShapeLayer绘制路径,但我是想知道是否有办法为图层的填充设置动画.

例如,我有一些我想在屏幕上绘制的文字,但我只能绘制文本的笔划而不是填充.另一个例子,我有一个星形,我想动画它被填充.

这可能使用CAShapeLayer或其他对象吗?

谢谢!

animation core-animation calayer cashapelayer ios

9
推荐指数
1
解决办法
5316
查看次数

从CGPath修剪/减去CGPath?

我有一些CGPath(一个带有两个圆圈的聚合物)在一个上进行CAShapeLayer.

我可以修剪/减去这样的路径吗?

在此输入图像描述

core-animation subtraction cashapelayer cgpath ios

9
推荐指数
1
解决办法
1516
查看次数

使用UIBezierPath和CAShapeLayer时出现"无效上下文0x0"

我的困境与这个SO线程中描述的困境非常相似.我阅读了该主题的每个答案,但无法找到解决我问题的任何答案.我已经将我的问题缩小到下面函数内的4行.4行中的每一行都输出了几行错误,我在下面列出了所有错误(我删除了重复项).

我试过移动[path closePath];到这4行以下,但它没有改变任何东西.我还在第一行之前设置了一个断点,并逐行手动完成了这个功能,而这只是造成严重破坏的4行.

对于这个问题似乎是一个趋势,一切都完全按照它应该呈现,但它充斥着控制台与这些类型的消息.

任何帮助将不胜感激,我很乐意提供更多信息和更新.


功能:

-(CAShapeLayer *)lineBetweenPoint:(CGPoint)start andPoint:(CGPoint)end {

    //Draw the first circle
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:start radius:kLineEndRadius startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];

    //Add the line
    [path moveToPoint:start];
    [path addLineToPoint:end];
    [path moveToPoint:end];

    //Draw the second circle
    [path addArcWithCenter:end radius:kLineEndRadius startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];

    //Close the path and set the coloring
    [path closePath];

    /*The following 4 lines cause problems*/
    [[UIColor blueColor] setStroke]; /*CAUSES PROBLEM*/
    [[UIColor blueColor] setFill]; /*CAUSES PROBLEM*/
    [path stroke]; /*CAUSES PROBLEM*/
    [path fill]; /*CAUSES PROBLEM*/

    //Create …
Run Code Online (Sandbox Code Playgroud)

objective-c cashapelayer ios uibezierpath

9
推荐指数
1
解决办法
6023
查看次数

使用CAShapeLayer对象使用Bezierpath绘制线条

我正在制作一个图像编辑器,可以创建不同的形状对象,如圆形,三角形和方形,也可以更新或删除.所以我用它CAShapeLayer来创建形状对象.

现在我也想在图像上画一条线也可以更新或删除所以我使用bezierpath并CAShapeLayer创建线,它工作正常.但现在的问题是,当我想选择任何现有线时,可以选择接近线工具的任何位置,因为CAShapeLayer还设置了从起点到终点的直线的填充区域.

我的问题是如何创建没有填充区域的线CAShapeLayer.

这是我创建行的代码:

CAShapeLayer *line = [CAShapeLayer layer];
// Using bezierpath to make line 
UIBezierPath *linePath=[UIBezierPath bezierPath];

// Creating L with line

[linePath moveToPoint:point1];
[linePath addToPoint:point2];
[linePath addToPoint:point3];
line.path=linePath.CGPath;


// Configure the appearence of the line
line.fillColor = Nil;
line.opacity = 1.0;
line.strokeColor = [UIColor whiteColor].CGColor;
Run Code Online (Sandbox Code Playgroud)

对此有任何想法将非常感激.

objective-c cashapelayer ios uibezierpath

8
推荐指数
1
解决办法
9947
查看次数

创建一个只有一个对角线的UIView

我需要创建一个左边框倾斜45度的UIView, 我想知道,有没有办法以编程方式实现这个?在这种情况下,CATransform3D是否对我有帮助,因为它不是真正的"3D旋转"?

编辑

这是一张图片,解释了我需要的更多输出

在此输入图像描述

uiview cashapelayer ios diagonal swift

8
推荐指数
1
解决办法
3966
查看次数

使用CAShapeLayer和UIBezierPath剪辑屏蔽uiview

我在使用CAShapeLayer-UIBezierPath剪切视图时遇到问题,我想剪切内容但最终得到了一个带有UIBezierPath的笔画(帧),这是我的代码

UIBezierPath *path2Path = [UIBezierPath bezierPath];
[path2Path moveToPoint:CGPointMake(206.745, 0)];
[path2Path addLineToPoint:CGPointMake(206.745, 97.613)];
[path2Path addLineToPoint:CGPointMake(0, 97.613)];
[path2Path addLineToPoint:CGPointMake(0, 0)];
[path2Path addLineToPoint:CGPointMake(87.28, 0)];
[path2Path addCurveToPoint:CGPointMake(103.808, 12.118) controlPoint1:CGPointMake(87.28, 0) controlPoint2:CGPointMake(86.555, 12.118)];
[path2Path addCurveToPoint:CGPointMake(119.466, 0) controlPoint1:CGPointMake(121.061, 12.118) controlPoint2:CGPointMake(119.466, 0)];
[path2Path addLineToPoint:CGPointMake(206.745, 0)];
[path2Path closePath];

[path2Path addClip];

CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame=MYVIEW.bounds;
pathLayer.path = path2Path.CGPath;

pathLayer.strokeColor = [[UIColor blackColor] CGColor];
pathLayer.fillColor = [[UIColor clearColor] CGColor];

pathLayer.fillRule=kCAFillRuleEvenOdd;
[MYVIEW.layer setMask:pathLayer];
[MYVIEW.layer setMasksToBounds:YES];

MYVIEW.backgroundColor=[UIColor greenColor];
Run Code Online (Sandbox Code Playgroud)

这段代码的结果只是一个绿色笔划线,边界是空的,就像这样 http://i.stack.imgur.com/aehdo.png

但是,我希望将界限设为绿色,并按中风进行修剪

objective-c uiview cashapelayer ios uibezierpath

8
推荐指数
2
解决办法
1万
查看次数

如何准确地在图像模式上画线

我有一个UIImageView.在里面,我正在画一条机智用户触摸事件.问题是可以在任何地方UIImageview绘制线条,但我喜欢仅使用图像模式绘制线条.

例如,看看这张图片.我只需要在图像模式上画线.

在此输入图像描述

这是我的代码:

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [[event allTouches] anyObject];
    touchPoint = [touch locationInView:self.imgColor];
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)];
    [path addLineToPoint:CGPointMake(startingPoint.x,startingPoint.y)];
    startingPoint=touchPoint;
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = [path CGPath];
    shapeLayer.strokeColor = [[UIColor blueColor] CGColor];
    shapeLayer.lineWidth = 3.0;
    shapeLayer.fillColor = [[UIColor redColor] CGColor];
    [self.imgColor.layer addSublayer:shapeLayer];
    [arrLayer addObject:shapeLayer];
    NSLog(@"Touch moving point =x : %f Touch moving point =y : %f", touchPoint.x, touchPoint.y);



}
Run Code Online (Sandbox Code Playgroud)

我希望有人解决我的问题.

objective-c uiimageview cashapelayer uigesturerecognizer ios

8
推荐指数
1
解决办法
567
查看次数