2016-04-13 16 views
0

UITableView hücrelerini uzun bastırma jest tanıyıcı kullanarak yeniden sıralamaya çalışıyorum. Hücre sunum katmanından UIGraphicsGetImageFromCurrentImageContext() kullandığımda CAAnimations geri döndürülür.UIGraphicsGetImageFromCurrentImageContext() CAAnimations dahil değil

// Kod preslenmiş

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() 

// Kod UIControl gelen alt sınıf bir görüntü yapmak için

//MARK: Properties 

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

// MARK: Kur

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") 

} 

cevap

0

giderildi

let cellImage = cell.snapshotViewAfterScreenUpdates (false)

İlgili konular