小编Old*_*ame的帖子

在路径上找到一个点

我有一个应用程序在a中绘制bezier曲线UIView,我需要在为Y设置值时找到X相交.首先,据我所知,没有办法直接找到一个点,UIBezierPath但你可以找到一点CGPath.

首先,如果我"抚摸"我UIBezierPath(就像我在我的代码中所做的那样)这实际上是在创建一个CGPath还是我需要采取进一步的步骤来实际将其转换为CGPath

其次,我想通过提供Y的值来找到在X处相交的曲线.

我的目的是当用户移动滑块(分别向左或向右移动曲线)时,自动计算给定Y值的X.

我的开始显示.

我的开始显示

当我调整滑块时会发生什么.

当我调整滑块时会发生什么

我希望我的显示器看起来像.

我希望我的显示器看起来像

GraphView.h

#import <UIKit/UIKit.h>

@interface GraphView : UIView
{
    float adjust;
    int x;
    int y;
}

- (IBAction)sliderChanged:(id)sender;
- (IBAction)yChanged:(id)sender;

@property (weak, nonatomic) IBOutlet UISlider *sliderValue;
@property (weak, nonatomic) IBOutlet UITextField *xValue;
@property (weak, nonatomic) IBOutlet UITextField *yValue;

@end
Run Code Online (Sandbox Code Playgroud)

GraphView.m

#import "GraphView.h"

@interface GraphView ()


@end

@implementation GraphView

@synthesize sliderValue, xValue, yValue;

- (id)initWithCoder:(NSCoder *)graphView
{
    self = [super initWithCoder:graphView];
    if (self) {
        adjust …
Run Code Online (Sandbox Code Playgroud)

algorithm objective-c cgpath uibezierpath

6
推荐指数
1
解决办法
1622
查看次数

Swift中的UIBezierPath Stroke(和Fill)

我正在努力找到一种方法来快速抚摸(并填充)Bezier路径.这是我认为会起作用但不起作用的.

var myBezier = UIBezierPath()
myBezier.moveToPoint(CGPoint(x: 0, y: 0))
myBezier.addLineToPoint(CGPoint(x: 100, y: 0))
myBezier.addLineToPoint(CGPoint(x: 50, y: 100))
myBezier.closePath()
UIColor.setStroke(UIColor.blackColor())
myBezier.stroke()
Run Code Online (Sandbox Code Playgroud)

该行在UIColor.setStroke(UIColor.blackColor())控制台中给出了这个错误:

Playground execution failed: error: <REPL>:51:1: error: expression
resolves to an unused function UIColor.blackColor())
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

该行myBezier.stroke()给了我这组错误:

Jul 19 12:07:46 Computer-MacBook-Pro.local [20579] <Error>: CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. …
Run Code Online (Sandbox Code Playgroud)

uibezierpath swift

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

CGAffineTransformIdentity和自动布局

是否可以将转换标识设置为当前转换状态?我关注的是使用自动布局,并且一旦应用了转换,框架现在是未定义的.这只是一个抽象的思维过程,实际上可能不是一个问题.

假设我应用了一个CGAffineTransformMakeScale(1,-1)翻转UIView一个超级视图的子视图.现在我已经将一个转换应用于subView框架:现在变得未定义,那么如果我调整superView的尺寸,那将如何影响superView中subView的大小和位置?

我的思维过程告诉我,如果我可以将"CGAffineTransformIdentity"设置为当前转换状态(例如在翻转或旋转之后),我设置的任何自动布局都将被正确处理,但如果没有设置,我将无法获得适当的自动布局处理.

所以我需要担心框架:未定义或自动布局是否使用转换视图的边界:?

identity transform objective-c uiview cgaffinetransform

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

设置IBOutletCollection的图层属性

我正在尝试设置连接到IBOutletCollection 的多个按钮的图层属性,但IBOutletCollection不允许我访问UIButton.layer与常规操作相同的按钮IBOutlet.

接口文件:

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *customButton;
@property (weak, nonatomic) IBOutlet UIButton *myButton;
Run Code Online (Sandbox Code Playgroud)

实施文件

myButton.layer.cornerRadius = 9; // this works for individual buttons
customButton.layer.cornerRadius = 9; //This doesn't work for the collection of buttons
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?我是否需要做其他事情来调整集合的图层属性?我已将QuartzCore导入到我的实现文件中.

我只是试图在集合中添加4个按钮,所以如果我必须单独设置每个按钮,它不是世界末日,但能够将它们组合在一起会很好.

xcode objective-c iboutlet iboutletcollection

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

将变量设置为CGPointMake

如何将变量设置为CGMakePoint

我已尝试通过以下方式设置和调用变量:

我期待这个工作.

float p0[] = {0, 100};

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:CGPointMake(p0)]; // this tells me I need two arguments
Run Code Online (Sandbox Code Playgroud)

不!

float *p0 = CGPointMake(0, 100);

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:p0];
Run Code Online (Sandbox Code Playgroud)

失败!

NSObject *p0 = CGPointMake(0, 100);

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:p0];
Run Code Online (Sandbox Code Playgroud)

另一个错误!

id p0 = CGPointMake(0, 100);

UIBezierPath *point = [[UIBezierPath alloc] init];
    [point moveToPoint:p0];
Run Code Online (Sandbox Code Playgroud)

参加课程!

NSString *p0 = @"CGPointMake(0, 100)";

UIBezierPath *point = [[UIBezierPath alloc] init]; …
Run Code Online (Sandbox Code Playgroud)

variables cocoa-touch objective-c cgpoint

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