Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS CALayer遮罩奇怪的半像素线_Ios_Calayer_Pixel_Cabasicanimation - Fatal编程技术网

iOS CALayer遮罩奇怪的半像素线

iOS CALayer遮罩奇怪的半像素线,ios,calayer,pixel,cabasicanimation,Ios,Calayer,Pixel,Cabasicanimation,我需要通过所有文本层将透明圆弧从0切割为圆周率。 除了一件事外,代码如下所示。 我在为掩蔽CALayer执行CABASICANIATION时有很小的宽度线,在空闲状态下没有奇怪的线 我不明白为什么它会出现,因为理论上它根本不需要是可见的 这是我的游乐场代码: import UIKit import PlaygroundSupport let rootView = UIView(frame: CGRect(x: 0, y: 0,

我需要通过所有文本层将透明圆弧从0切割为圆周率。 除了一件事外,代码如下所示。 我在为掩蔽CALayer执行CABASICANIATION时有很小的宽度线,在空闲状态下没有奇怪的线

我不明白为什么它会出现,因为理论上它根本不需要是可见的

这是我的游乐场代码:

import UIKit
import PlaygroundSupport

let rootView = UIView(frame: CGRect(x: 0, y: 0,
                                    width: 200,
                                    height: 200))
rootView.backgroundColor = .gray

let uiview = UIButton(frame: CGRect(x: 0,
                                  y: 0,
                                  width: 200,
                                  height: 200))
uiview.setTitle("H", for: .normal)
uiview.titleLabel?.font = UIFont.boldSystemFont(ofSize: 200)
uiview.setTitleColor(.black, for: .normal)
uiview.backgroundColor = UIColor.green
uiview.layer.cornerRadius = 100
uiview.layer.masksToBounds = true
rootView.addSubview(uiview)

let center = CGPoint(x: uiview.bounds.width / 2,
                     y: uiview.bounds.height / 2)

let path = UIBezierPath(arcCenter: center,
                        radius: 80,
                        startAngle: 0,
                        endAngle: .pi,
                        clockwise: true)
path.append(UIBezierPath(arcCenter: center,
                         radius: 78,
                         startAngle: -1,
                         endAngle: .pi,
                         clockwise: true))
path.append(UIBezierPath(rect: uiview.bounds))

let maskLayer = CAShapeLayer()
maskLayer.frame = uiview.bounds
maskLayer.path = path.cgPath
maskLayer.backgroundColor = UIColor.clear.cgColor
maskLayer.fillRule = kCAFillRuleEvenOdd
maskLayer.lineWidth = 0

uiview.layer.mask = maskLayer

let rotation = CABasicAnimation(keyPath: "transform.rotation")
rotation.fromValue = 0.0
rotation.toValue = Double.pi * 2
rotation.duration = 10
rotation.repeatCount = 2
maskLayer.add(rotation, forKey: nil)


PlaygroundPage.current.liveView = rootView

如何解决这个问题?

只需做一些小改动,如:

path.append(UIBezierPath(arcCenter: center,
                         radius: 78,
                         startAngle: .pi,
                         endAngle: 0,
                         clockwise: false))
动画的最后几秒钟如下所示:

这两条弧线彼此错位

那么,发生了什么变化:

  • 第二个弧的起始角为π

  • 它的终止角为0

  • 顺时针方向设置为false

这就是你要找的吗