gpt4 book ai didi

ios - UIGraphicsGetImageFromCurrentImageContext() 不包括 CAAnimations

转载 作者:行者123 更新时间:2023-11-30 13:30:36 26 4
gpt4 key购买 nike

我正在尝试使用长按手势识别器重新排序 UITableView 单元格。当我从单元格表示层使用 UIGraphicsGetImageFromCurrentImageContext() 时,CAAnimations 将被恢复。

//从按下的 uitableviewcell 生成图像的代码

UIGraphicsBeginImageContextWithOptions(cell.bounds.size, false, 0)
if let layer = cell.layer.presentationLayer() {
layer.renderInContext(UIGraphicsGetCurrentContext()!)
} else {
cell.layer.renderInContext(UIGraphicsGetCurrentContext()!)
}
let cellImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

//UIControl 子类的代码

//MARK: Properties

var switchControl = CAShapeLayer()
var backgroundLayer = CAShapeLayer()

//标记:设置

override func setUpView(){
super.setUpView()
didSetUpView = true
self.backgroundColor = UIColor.clearColor()
let frame = CGRectMake(0, 0, self.bounds.width, self.bounds.height)
let radius = self.bounds.height/2 - lineWidth
let roundedRectPath = UIBezierPath(roundedRect:CGRectInset(frame, lineWidth, lineWidth) , cornerRadius:radius)
backgroundLayer.fillColor = stateToFillColor(isOn)
backgroundLayer.strokeColor = lineColor.CGColor
backgroundLayer.lineWidth = lineWidth
backgroundLayer.path = roundedRectPath.CGPath
self.layer.addSublayer(backgroundLayer)

let innerLineWidth = self.bounds.height - lineWidth*3 + 1
let switchControlPath = UIBezierPath()
switchControlPath.moveToPoint(CGPointMake(lineWidth, 0))
switchControlPath.addLineToPoint(CGPointMake(self.bounds.width - 2 * lineWidth - innerLineWidth + 1, 0))
var point = backgroundLayer.position
point.y += (radius + lineWidth)
point.x += (radius)
switchControl.position = point
switchControl.path = switchControlPath.CGPath
switchControl.lineCap = kCALineCapRound
switchControl.fillColor = nil
switchControl.strokeColor = circleColor.CGColor
switchControl.lineWidth = innerLineWidth
switchControl.strokeEnd = 0.0001
self.layer.addSublayer(switchControl)
changeValueAnimate(isOn,duration: animateDuration)
}

//MARK: - Animate

func changeValueAnimate(turnOn:Bool, duration:Double){

let times = [0,0.49,0.51,1]

let switchControlStrokeStartAnim = CAKeyframeAnimation(keyPath:"strokeStart")
switchControlStrokeStartAnim.values = turnOn ? [0,0,0,1] : [1,0,0, 0]
switchControlStrokeStartAnim.keyTimes = times
switchControlStrokeStartAnim.duration = duration
switchControlStrokeStartAnim.removedOnCompletion = true

let switchControlStrokeEndAnim = CAKeyframeAnimation(keyPath:"strokeEnd")
switchControlStrokeEndAnim.values = turnOn ? [0,1,1,1] : [1,1,1,0]
switchControlStrokeEndAnim.keyTimes = times
switchControlStrokeEndAnim.duration = duration
switchControlStrokeEndAnim.removedOnCompletion = true


let backgroundFillColorAnim = CAKeyframeAnimation(keyPath:"fillColor")
backgroundFillColorAnim.values = [stateToFillColor(!turnOn),
stateToFillColor(!turnOn),
stateToFillColor(turnOn),
stateToFillColor(turnOn)]
backgroundFillColorAnim.keyTimes = [0,0.5,0.51,1]
backgroundFillColorAnim.duration = duration
backgroundFillColorAnim.fillMode = kCAFillModeForwards
backgroundFillColorAnim.removedOnCompletion = false


if rotateWhenValueChange{
UIView.animateWithDuration(duration, animations: { () -> Void in
self.transform = CGAffineTransformRotate(self.transform, CGFloat(M_PI))
})
}

UIView.animateWithDuration(duration / 3, animations: {
self.transform = CGAffineTransformMakeScale(1.15, 1.15)
}) { (animate: Bool) in
UIView.animateWithDuration(duration / 3 * 2, animations: {
self.transform = CGAffineTransformMakeScale(1.0, 1.0)
})
}

let switchControlChangeStateAnim : CAAnimationGroup = CAAnimationGroup()
switchControlChangeStateAnim.animations = [switchControlStrokeStartAnim,switchControlStrokeEndAnim]
switchControlChangeStateAnim.fillMode = kCAFillModeForwards
switchControlChangeStateAnim.removedOnCompletion = false
switchControlChangeStateAnim.duration = duration

let animateKey = turnOn ? "TurnOn" : "TurnOff"
switchControl.addAnimation(switchControlChangeStateAnim, forKey: animateKey)
backgroundLayer.addAnimation(backgroundFillColorAnim, forKey: "Color")

}

最佳答案

问题已解决

让 cellImage = cell.snapshotViewAfterScreenUpdates(false)

关于ios - UIGraphicsGetImageFromCurrentImageContext() 不包括 CAAnimations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36610052/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com