标签: uibezierpath

设置 CAShapeLayer lineWidth 小于 1

在上面的屏幕截图中,有两行:

  1. 实线只是UIView高度为 1px 的线
  2. 使用此代码创建虚线

- (void)viewDidAppear:(BOOL)animated {
    CAShapeLayer *line = [CAShapeLayer layer];
    UIBezierPath *linePath=[UIBezierPath bezierPath];

    [linePath moveToPoint:CGPointMake(0, 107)];
    [linePath addLineToPoint:CGPointMake(self.view.frame.size.width, 107)];

    line.lineWidth = 0.5;
    line.path=linePath.CGPath;
    line.fillColor = [[UIColor blackColor] CGColor];
    line.strokeColor = [[UIColor blackColor] CGColor];

    [line setLineJoin:kCALineJoinRound];
    [line setLineDashPattern: [NSArray arrayWithObjects:[NSNumber numberWithInt:10], [NSNumber numberWithInt:5],nil]];

    [[self.view layer] addSublayer:line];
}
Run Code Online (Sandbox Code Playgroud)

为什么UIView1 像素 ( 1.0) 的高度小于虚线的0.5高度?

我希望虚线和实线一样细。

objective-c cashapelayer ios uibezierpath

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

UIButton 中的 UIBezierPath 圆角

我想在文本周围绘制一个可点击的气泡形状。为了做到这一点,我决定向 UIButton 添加一个 shapelayer,如下所示:

// Button also has this
bubbleButton.contentEdgeInsets = UIEdgeInsets(top: 5, left: 10, bottom: 5, right: 10)
bubbleButton.setTitle("Gutp", for: .normal)

// In my subclass of UIButton
override func layoutSubviews() {
    super.layoutSubviews()

    self.bubbleLayer?.removeFromSuperlayer()

    let maskLayer = CAShapeLayer.init()
    let bezierPath = UIBezierPath.init(roundedRect: self.bounds,
                                       byRoundingCorners: [.topRight, .topLeft, .bottomLeft],
                                       cornerRadii: CGSize(width: 20, height: 20))
    maskLayer.path = bezierPath.cgPath
    maskLayer.strokeColor = UIColor.red.cgColor
    maskLayer.lineWidth = 2
    maskLayer.fillColor = UIColor.clear.cgColor
    maskLayer.backgroundColor = UIColor.clear.cgColor
    maskLayer.isOpaque = false

    self.bubbleLayer = maskLayer

    if let layers = self.layer.sublayers {
        self.layer.insertSublayer(self.bubbleLayer!, …
Run Code Online (Sandbox Code Playgroud)

uibutton ios uibezierpath swift

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

如何在 Swift 4 中使用 CAShapeLayer 和 BezierPath 绘制曲线?

我想知道如何在 Swift 4 中使用 CAShapeLayer 和 BezierPath 给定两个点(A 点和 B 点)渲染一条如下图所示的曲线?

func drawCurvedLine(start: CGPoint, end: CGPoint) {
   //insert code here
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

core-graphics cashapelayer ios uibezierpath swift4

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

具有流畅/弹性笔画的圆圈

我和我的团队正在为客户开发一款应用程序。我们正在尝试了解如何实现这种动画(仅指圆形笔画):

在此输入图像描述

我们尝试使用 aCADisplayLink来设置和更改圆,但它生成了不流畅的结果。我们无法找到一种方法来从“组件”创建一个圆UIBezierPath并更改每个锚点。

任何有关如何实现这种效果或如何从单独的点构建圆的建议都将受到高度重视

谨致问候,
Roi 和团队

ios cadisplaylink uibezierpath

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

带有圆角的 UIBezierPath Star

我使用以下代码通过 UIBezierPath 创建了一个星形图像:

    let path = UIBezierPath()
    let center = CGPoint(x: rect.width / 2.0, y: rect.height / 2.0)
    let xCenter: CGFloat = center.x
    let yCenter: CGFloat = center.y
    let w = rect.width
    let r = w / 2.0
    let flip: CGFloat = -1.0 // use this to flip the figure 1.0 or -1.0
    let polySide = CGFloat(5)
    let theta = 2.0 * Double.pi * Double(2.0 / polySide)
    path.move(to: CGPoint(x: xCenter, y: r * flip + yCenter))
    for i in 1..<Int(polySide) …
Run Code Online (Sandbox Code Playgroud)

ios uibezierpath swift

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

如何从 CAShapeLayer 获取坐标

所以我正在尝试制作一个进度条。所以我制作了圆形路径,但我希望点位于进度条的末尾,但是如何使点的位置位于当前进度的末尾?

private func simpleShape() {
  let width: CGFloat = 10
  createCircle()

  //make circle transparant in middle
  progressLayer.fillColor = UIColor.clear.cgColor
  progressLayer.strokeColor = UIColor.blue.cgColor
  progressLayer.lineCap = CAShapeLayerLineCap.round
  progressLayer.lineWidth = width
  progressLayer.strokeStart = 0
  progressLayer.strokeEnd = 0

  //unfilled
  backLayer.lineWidth = width
  backLayer.strokeColor = #colorLiteral(red: 0.1411764706, green: 0.1725490196, blue: 0.2431372549, alpha: 1).cgColor
  backLayer.strokeEnd = 1

  self.layer.addSublayer(gradientLayer)
}

private func createCircle() {

  //create circle
  let circle = UIView(frame: bounds)
  circle.layoutIfNeeded()
  let centerPoint = CGPoint (x: circle.bounds.width / 2, y: circle.bounds.width / 2)
  let circleRadius: CGFloat …
Run Code Online (Sandbox Code Playgroud)

xcode calayer ios uibezierpath swift

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

平滑地动画 CAShapeLayer 路径

我正在尝试制作一个 Gauge UIView 来尽可能模仿以下图像 目标

    func gradientBezierPath(percent: CGFloat) ->  UIBezierPath {
        // vary this to move the start of the arc
        let startAngle = CGFloat(180).toRadians()//-CGFloat.pi / 2  // This corresponds to 12 0'clock
        // vary this to vary the size of the segment, in per cent
        let proportion = CGFloat(50 * percent)
        let centre = CGPoint (x: self.frame.size.width / 2, y: self.frame.size.height / 2)
        let radius = self.frame.size.height/4//self.frame.size.width / (CGFloat(130).toRadians())
        let arc = CGFloat.pi * 2 * proportion / 100 // …
Run Code Online (Sandbox Code Playgroud)

animation cabasicanimation ios uibezierpath swift

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

如何追踪 iPhone 屏幕的边框(包括 X、11 或 12 系列的凹口)?

我试图在主视图的外部追踪一条线 - 沿着屏幕边缘追踪。下图显示了轮廓,下面的代码显示了它的动画效果。

iPhone边框

问题是,动画首先绘制外边缘,然后绘制凹口周围的区域。

我需要它开始绘制外边缘,下拉并围绕凹口绘制,然后沿着外边缘继续绘制,直到完成。

import UIKit

class ViewController: UIViewController {
    
    var layer: CAShapeLayer = CAShapeLayer()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupBorder()
        animateBorder()
    }
    
    func setupBorder() {
        let bounds = self.view.bounds
        
        if UIDevice.current.hasNotch {
        
            // FIXME: needs tweaks for:
            // 12 pro max (corners and notch)
            // 12 pro (corners)
            // 12 mini (notch)
            // the math works for all X and 11 series
            
            // border around the phone screen
            let framePath = UIBezierPath(roundedRect: bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 40, …
Run Code Online (Sandbox Code Playgroud)

xcode cashapelayer uibezierpath swift

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

在 iOS 中创建带有渐变的折线图

在 iOS 中创建这样的图表的最佳方法是什么?

在此输入图像描述

我的第一个想法是创建一条贝塞尔曲线路径,然后添加具有不同位置的渐变层。但这是行不通的,因为文档指定:

这些值必须单调递增。

我的图表中情况并非如此。

关于实现这一目标的好方法有什么想法吗?

谢谢

gradient ios uibezierpath cagradientlayer swift

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

iOS:反向UIBezierPath(bezierPathWithOvalInRect)

我有一个jpg图像与矩形中的圆形对象,并希望使圆形对象的envoirement透明...

例

(在此示例中删除红色区域)

在这个iOS的帮助下,UIImage透明和"UIBezierPath bezierPathWithOvalInRect"的一部分我已经取得了一些成功,但这会围绕我的对象形成一条路径,我需要将其反转,以使外部而不是内部路径透明..

我不知道在哪里我必须更改我的代码以获得正确的结果..

这是我的代码:

//BezierPath
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)];  

// Create an image context containing the original UIImage.
UIGraphicsBeginImageContext(_imgTemp.image.size);
[_imgTemp.image drawAtPoint:CGPointZero];

// Clip to the bezier path and clear that portion of the image.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context,bezierPath.CGPath);
CGContextClip(context);
CGContextClearRect(context,CGRectMake(0,0,self._imgTemp.image.size.width,self._imgTemp.image.size.height));

// Build a new UIImage from the image context.
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self._imgTemp.image = newImage;
Run Code Online (Sandbox Code Playgroud)

有人解决了吗?

transparency image core-graphics ios uibezierpath

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