GVKun编程网logo

swift – NSRectFill和NSBezierPath(rect)之间有什么区别.fill(swift和cinder区别)

4

在本文中,我们将为您详细介绍swift–NSRectFill和NSBezierPath(rect)之间有什么区别.fill的相关知识,并且为您解答关于swift和cinder区别的疑问,此外,我们还会

在本文中,我们将为您详细介绍swift – NSRectFill和NSBezierPath(rect)之间有什么区别.fill的相关知识,并且为您解答关于swift和cinder区别的疑问,此外,我们还会提供一些关于animation – 在drawRect()Swift中绘制bezier路径的动画、c – CRect c之间有什么区别;和CRect c();什么时候CRect是一个类?、Directory.EnumerateFiles 与 Directory.GetFiles 有什么区别?、Directory.EnumerateFiles与Directory.GetFiles有什么区别?的有用信息。

本文目录一览:

swift – NSRectFill和NSBezierPath(rect)之间有什么区别.fill(swift和cinder区别)

swift – NSRectFill和NSBezierPath(rect)之间有什么区别.fill(swift和cinder区别)

我知道我可以使用NSRectFill(bounds)填充矩形.但是我想保留PDF输出的透明度,我发现只能使用NSBezierPath(rect:bounds).fill()
这两者有什么不同(幕后)?

func drawBackground() {
    CGContextSaveGState(currentContext)
    if (NSGraphicsContext.currentContextDrawingToScreen()) {
        NSColor(patternImage: checkerboardImage).set()
        NSRectFillUsingOperation(bounds,NSCompositingOperation.CompositeSourceOver)
    }
    NSColor.clearColor().setFill()
    //NSRectFill(bounds) //option 1
    NSBezierPath(rect: bounds).fill() // option 2
    CGContextRestoreGState(currentContext)
}

extension NSImage {

    static func checkerboardImageWithSize(size : CGFloat) -> NSImage {
        let fullRect = NSRect(x: 0,y: 0,width: size,height: size)
        let halfSize : CGFloat = size * 0.5;
        let upperSquareRect = NSRect(x: 0,width: halfSize,height: halfSize);
        let bottomSquareRect = NSRect(x: halfSize,y: halfSize,width:halfSize,height: halfSize);
        let image = NSImage(size: NSSize(width: size,height: size))
        image.lockFocus()
        NSColor.whiteColor()
        NSRectFill(fullRect)
        NSColor(deviceWhite: 0.0,alpha:0.1).set()
        NSRectFill(upperSquareRect)
        NSRectFill(bottomSquareRect)
        image.unlockFocus()
        return image
    }
}

解决方法

我大部分时间都是iOS程序员,而且在AppKit方面这些日子并不是很流畅,但我的猜测是你得到了错误的NSCompositingOperation.我从文档中看到NSRectFill使用NSCompositecopy.如果您使用NSRectFillUsingOperation,可能会更好地工作,您可以在其中指定合成操作.

animation – 在drawRect()Swift中绘制bezier路径的动画

animation – 在drawRect()Swift中绘制bezier路径的动画

我有这个形状,我在drawRect()中绘制
var rectanglePath = UIBezierPath()

override func drawRect(rect: CGRect) {
    rectanglePath = UIBezierPath(rect: self.bounds)
    rectanglePath.fillWithBlendMode(kCGBlendModeMultiply,alpha: 0.7)
    layer.shouldRasterize = true
}

当调用prepareForEditing函数时,我想为rectanglePath设置动画.我试过了

func prepareForEditing(editing:Bool){
        UIView.animateWithDuration(0.5,animations: {
              self.rectanglePath = makeNewShape()
            }
       )
  }

什么都没发生.你能告诉我我的代码有什么问题吗?

要为CGPath设置动画,您不能使用UIView.animation方法.
我创建了自定义UIView子类来向您展示如何为CGPaths形状设置动画,请参考注释并根据您的要求进行修改:
class MyView: UIView {

let shapeLayer = CAShapeLayer()
let maskLayer = CAShapeLayer()
var rectanglePath = UIBezierPath()

override func didMovetoSuperview() {
    super.didMovetoSuperview()

    backgroundColor = UIColor.clear

    // initial shape of the view
    rectanglePath = UIBezierPath(rect: bounds)

    // Create initial shape of the view
    shapeLayer.path = rectanglePath.cgPath
    shapeLayer.strokeColor = UIColor.black.cgColor
    shapeLayer.fillColor = UIColor.clear.cgColor
    layer.addSublayer(shapeLayer)

    //mask layer
    maskLayer.path = shapeLayer.path
    maskLayer.position =  shapeLayer.position
    layer.mask = maskLayer
}

func prepareForEditing(editing:Bool){

    let animation = CABasicAnimation(keyPath: "path")
    animation.duration = 2

    // Your new shape here
    animation.tovalue = UIBezierPath(ovalIn: bounds).cgPath
    animation.timingFunction = camediatimingFunction(name: kcamediatimingFunctionEaSEOut)

    // The next two line preserves the final shape of animation,// if you remove it the shape will return to the original shape after the animation finished
    animation.fillMode = kCAFillModeForwards
    animation.isRemovedOnCompletion = false

    shapeLayer.add(animation,forKey: nil)
    maskLayer.add(animation,forKey: nil)
  }
}

c – CRect c之间有什么区别;和CRect c();什么时候CRect是一个类?

c – CRect c之间有什么区别;和CRect c();什么时候CRect是一个类?

CRect c之间有什么区别;和CRect c(),当CRect是一个类?

解决方法

这个

CRect c;

创建一个名为c的CRect对象.

这个

CRect c();

声明一个名为c()的函数,它返回一个CRect对象.这是一个令人烦恼的解析,然而,它不是most vexing one.

Directory.EnumerateFiles 与 Directory.GetFiles 有什么区别?

Directory.EnumerateFiles 与 Directory.GetFiles 有什么区别?

Directory.EnumerateFilesvs 和有什么不一样GetFiles

显然,一个返回一个数组,另一个返回 Enumerable。

还要别的吗?

Directory.EnumerateFiles与Directory.GetFiles有什么区别?

Directory.EnumerateFiles与Directory.GetFiles有什么区别?

Directory.EnumerateFilesvs和有GetFiles什么区别?

显然,一个返回数组,另一个返回Enumerable。

还要别的吗?

关于swift – NSRectFill和NSBezierPath(rect)之间有什么区别.fillswift和cinder区别的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于animation – 在drawRect()Swift中绘制bezier路径的动画、c – CRect c之间有什么区别;和CRect c();什么时候CRect是一个类?、Directory.EnumerateFiles 与 Directory.GetFiles 有什么区别?、Directory.EnumerateFiles与Directory.GetFiles有什么区别?的相关信息,请在本站寻找。

本文标签: