相关疑难解决方法(0)

使用UIBezierPath绘制图形曲线

我正在申请中绘制图表.我的问题是我想画线连接顶点作为曲线.目前我正在绘制它们UIBezierPath的功能addLineToPoint:.我想把它们画成曲线.我很清楚,UIBezierPath有以下两个功能来支持此功能.

立方曲线:addCurveToPoint:controlPoint1:controlPoint2: 二次曲线:addQuadCurveToPoint:controlPoint:

但问题是我没有控制点.我只有两个终点.我都没有找到确定控制点的方法/公式.有人能帮我一下吗?如果有人能提出一些替代方案我会很感激......

iphone core-graphics objective-c ios uibezierpath

15
推荐指数
5
解决办法
2万
查看次数

坐标中两条线之间的交点

我可以检测到两条线的交点,但是如果我的线没有我的屏幕的长度,它会检测到它不应该在的点.

这是预览: 路口 因此,它不应该检测到这个交叉点,因为水平线不是那么长.

码:

- (NSMutableArray *) intersectWithLines:(CGPoint)startPoint andEnd:(CGPoint)endPoint {
    NSMutableArray *intersects = [[NSMutableArray alloc] init];

    for(GameLine *line in [_lineBackground getLines]) {

        double lineStartX = line.startPos.x;
        double lineStartY = line.startPos.y;
        double tempEndX = line.endPos.x;
        double tempEndY = line.endPos.y;

        double d = ((startPoint.x - endPoint.x)*(lineStartY - tempEndY)) - ((startPoint.y - endPoint.y) * (lineStartX - tempEndX));

        if(d != 0) {            
            double sX = ((lineStartX - tempEndX) * (startPoint.x * endPoint.y - startPoint.y * endPoint.x) - (startPoint.x - endPoint.x) * (lineStartX * tempEndY …
Run Code Online (Sandbox Code Playgroud)

iphone math 2d intersection objective-c

6
推荐指数
3
解决办法
6290
查看次数

IOS:可以在每个角落使用不同值的圆形半径

我想我的全才UIView与这样的价值
top-left-radius:20; bottom-right-radius:5; bottom-left-radius:5;top-right-radius:10;

   //For rounder `UIRectCornerBottomLeft & UIRectCornerBottomRight` I use

    UIBezierPath *maskPath0 = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(5.0, 5.0)];

    CAShapeLayer *maskLayer0 = [[CAShapeLayer alloc] init];
    maskLayer0.frame = self.bounds;
    maskLayer0.path  = maskPath0.CGPath;
    self.messageView.layer.mask = maskLayer0;


    //For rounder `TopRight` I use

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)];

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


    //For rounder `TopLeft` I use

    UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopLeft) cornerRadii:CGSizeMake(20.0, …
Run Code Online (Sandbox Code Playgroud)

layer ios uibezierpath

6
推荐指数
2
解决办法
1291
查看次数

如何创建一个随机闭合的平滑CGPath?

我试图找到一种方法来创建一个随机的闭合平滑路径(CGPathUIBezierPath).我已经阅读了关于De Casteljau的算法以及关于Bezier路径的其他文章,但它似乎不适合我试图实现的目标.

我想过创建一个CGPath圆圈.然后我会通过一个函数来增加路径,这个函数会扭曲点的位置,比如正弦或余弦.但是我不知道这是否是正确的方向,因为路径不会有随机的形状.

CGMutablePathRef circle = CGPathCreateMutable();
CGPathAddArc(circle, nil, 0.0f, 0.0f, 100.0f, 2 * M_PI, 0.0f, true);
...
CGPathRelease(circle);
Run Code Online (Sandbox Code Playgroud)

如果有人能指出我正确的方向如何开始实施它将是伟大的.我尝试生成的路径示例:

在此输入图像描述

cocoa-touch objective-c cgpath ios uibezierpath

4
推荐指数
1
解决办法
1790
查看次数

UIBezierPath 用于手指触摸绘制的平滑曲线

我想平滑手指触摸绘制线上的曲线,我想要 UIBezierPath 中的解决方案,只有我的代码不完全平滑线。我的代码在这里

@implementation MyLineDrawingView
@synthesize undoSteps;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

        [super setBackgroundColor:[UIColor whiteColor]];

        pathArray=[[NSMutableArray alloc]init];
        bufferArray=[[NSMutableArray alloc]init];



    }
    return self;
}


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

    [[UIColor blackColor] setStroke];
    for (UIBezierPath *_path in pathArray) 
    [_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];    
}
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [bufferArray removeAllObjects];
    myPath=[[UIBezierPath alloc]init];
    myPath.lineWidth=5;
    myPath.miterLimit=-10; …
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c ipad ios

3
推荐指数
1
解决办法
7205
查看次数