我想使用UIBezierPath创建一个带圆角的多边形.我相信这可以使用addCurveToPoint:controlPoint1:controlPoint2:
和http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit中的类似代码,但我想知道是否有任何现有(或更好)的方法来实现这一目标?
我应该指出,这将需要针对任何凸多边形(例如在voronoi图中找到)而不仅仅是矩形形状.
我成功创建了UIBezierPath
现在我想在UIView中拖动该事件在拖动事件(UIPanGestureRecognizer
)上并获取该路径所争论的当前位置点.
是否有可能我们只能将UIBezierPath从一个地方拖到另一个地方?在UIView.
我希望使用UIBezier Path实现图像中显示的形状,并且图像中的块填充了形状,它显示了一个块被填充,如何实现这一点.
我从这里尝试了以下代码
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 10)];
[path addQuadCurveToPoint:CGPointMake(200, 10) controlPoint:CGPointMake(100, 5)];
[path addLineToPoint:CGPointMake(200, 0)];
[path addLineToPoint:CGPointMake(0, 0)];
[path closePath];
Run Code Online (Sandbox Code Playgroud)
谢谢.
我试图在UIView类别中使用UIBezierPath创建一个三角形.但没有显示三角形.还得到一个:CGContextSetFillColorWithColor.所以我的问题是如何使用UIView类别制作三角形或任何路径.演示项目
#import "UIView+Bubble.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIView (Bubble)
+(UIView *)makeBubble{
UIView *customView = [[UIView alloc] init];
customView.frame=CGRectMake(0, 0, 320, 500);
UIBezierPath *triangle = [UIBezierPath bezierPath];
[triangle moveToPoint:CGPointMake(100, 0)];
[triangle addLineToPoint:CGPointMake(0, 100)];
[triangle addLineToPoint:CGPointMake(200, 100)];
[triangle closePath];
[[UIColor blackColor] setFill];
[triangle fill];
customView.layer.shadowPath = [triangle CGPath];
return customView;
}
@end
Run Code Online (Sandbox Code Playgroud)
在ViewController.m中使用它像: -
- (void)viewDidLoad
{
UIView *helpBubble=[UIView makeBubble];
[self.view addSubview:helpBubble];
}
Run Code Online (Sandbox Code Playgroud) 我正在使用以下UIBezierPath
方法绘制椭圆:
UIBezierPath *bpath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, y, width, height)];
Run Code Online (Sandbox Code Playgroud)
这给了我类似下面的内容:
但我想以如下角度绘制椭圆:
我知道一个解决方案是旋转UIView
.但我不能这样做,因为同一个视图包含其他bezier路径.所以我想知道是否有办法以一定的角度绘制这个椭圆?
我希望startAngle处于90度,即π/ 2,所以我想如果我将endAngle设为90度,那么它只会形成一个完整的圆,但是没有绘制任何东西.
当我将开始和结束角度设置为如下所示的不同程度时,绘制路径,但它不是一个完整的圆.
下面是我目前使用的代码,但是如果startAngle是90度以便绘制一个完整的圆圈,我似乎无法弄清楚endAngle应该是什么.
有人可以帮忙吗?
override func drawRect(rect: CGRect) {
let center = CGPoint(x: bounds.width / 2, y: bounds.height / 2)
let radius: CGFloat = max(bounds.width, bounds.height)
let startAngle: CGFloat = 3 * ? / 4
let endAngle: CGFloat = ? / 4
var path = UIBezierPath(arcCenter: center,
radius: bounds.width / 2 - arcWidth / 2,
startAngle: startAngle,
endAngle: endAngle,
clockwise: true)
path.lineWidth = arcWidth
path.lineCapStyle = kCGLineCapRound
counterColor.setStroke()
path.stroke()
}
Run Code Online (Sandbox Code Playgroud) 我一直在试图弄清楚如何在这个项目中使用UIBezierPath,但我不知道如何实现这种绘图.我可以绘制一个圆弧,直线和直线,但我觉得这个很丢失.感谢帮助
我正在使用swift 2.2并且我正在处理这样的问题:我有一个UIBezier对象的数组,我需要为它们创建一个笔划作为一个路径.
我以前有一个特殊的功能,但这种方法的优点,它创建了几个层.这符合我的要求,因为我需要一层
func createStroke(line: UIBezierPath) {
self.currentPath = CAShapeLayer()
currentPath.path = line.CGPath
currentPath.strokeColor = UIColor.blackColor().CGColor
currentPath.fillColor = UIColor.clearColor().CGColor
currentPath.lineWidth = 1
self.view.layer.addSublayer(currentPath)
}
Run Code Online (Sandbox Code Playgroud)
从贝塞尔线阵列创建多路径的最佳方法是什么?第一个想法是创建一个for循环循环,但我认为它不是一个干净的方式.
我正在尝试制作一个为用户绘制对象的应用程序.我现在有一个这样的对象,它是由一个类型的数组构成的[UIBezierPath]
.然后我使用循环UIBezierPath
将数组中的所有s 更改为CGPath
s,然后想要逐个绘制那些路径的动画.但是,当我尝试使用此代码时,它不起作用,我无法在网上找到任何有用的信息.这是代码被使用来转换阵列macbookPath
它由UIBezierPath
成CGPath
:
for path in macbookPath {
drawingPath.append(path.cgPath)
}
Run Code Online (Sandbox Code Playgroud)
然后我使用此代码尝试绘制路径:
for cgPath in drawingPath {
shapeLayer.path = cgPath
}
Run Code Online (Sandbox Code Playgroud)
这是函数的其余代码,drawForm()
它应该将表单绘制到一个名为的视图上aiDrawView
:
@objc func drawForm() {
var drawingPath = [CGPath]()
var macbookPath = Forms.MacbookForm()
let shapeLayer = CAShapeLayer()
shapeLayer.frame = aiDrawView.bounds
for path in macbookPath {
drawingPath.append(path.cgPath)
}
for cgPath in drawingPath {
shapeLayer.path = cgPath
}
let strokeEndAnimation = CABasicAnimation(keyPath: "strokeEnd")
strokeEndAnimation.duration = 2.0
strokeEndAnimation.fromValue …
Run Code Online (Sandbox Code Playgroud) uibezierpath ×10
ios ×6
objective-c ×4
swift ×4
iphone ×3
cashapelayer ×2
arrays ×1
bezier ×1
cgpath ×1
cocoa-touch ×1
ellipse ×1
polygon ×1
quartz-2d ×1
uiimage ×1
uiview ×1
xcode ×1