2017-01-22 7 views
1

Swift 3.02 (Xcode 8.2)를 사용하면 응답 : https://stackoverflow.com/a/31450475/7448394에 설명 된 실행 취소 해결책을 참조합니다.redo가 작동하지 않습니다. (ios swift undoManager, Invocation)

아래 코드에서이 솔루션을 사용하여 도면의 실행 취소와 다시 실행을 테스트합니다. randomDrawing을 위해 버튼을 누르면 빨간 선이 0에서 임의의 점으로 그립니다. 실행 취소 버튼을 누르면이 행이 표시되거나 마지막 행이 사라집니다. 그러나 redo-button을 누르면 imageView에 아무런 변화가 없습니다. 분명히 실행 취소가 작동 중입니다. 실행 취소 작업 후에 true로 변경되는 undoManager? .canRedo도 확인했지만이 재실행 작업이 결과를 표시하지 않는 이유는 무엇입니까?

import UIKit 

클래스의 ViewController :의 UIViewController {

@IBOutlet var imageView: UIImageView! 

override func viewDidLoad() { 
    super.viewDidLoad() 
} 
override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
} 
@IBAction func undoDrawing(_ sender: AnyObject) { 
    undoManager?.undo() 
} 
@IBAction func redoDrawing(_ sender: AnyObject) { 
    undoManager?.redo() 
} 
@IBAction func randomDrawing(_ sender: AnyObject) { 
    let undo: UIImageView = undoManager?.prepare(withInvocationTarget: imageView) as! UIImageView 

    UIGraphicsBeginImageContext(self.imageView.frame.size) 
     self.imageView.image?.draw(in: CGRect(x: 0, y: 0, width: self.imageView.frame.size.width, height: self.imageView.frame.size.height)) 

     UIGraphicsGetCurrentContext()?.move(to: CGPoint(x: 0, y: 0))     
     UIGraphicsGetCurrentContext()?.addLine(to: CGPoint(x: Int(arc4random_uniform(100) + 100), y: Int(arc4random_uniform(100) + 100))) 
     UIGraphicsGetCurrentContext()?.setLineWidth(10.0) 
     UIGraphicsGetCurrentContext()?.setStrokeColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0) 
     UIGraphicsGetCurrentContext()?.strokePath() 

     undo.image = imageView.image 
     self.imageView.image = UIGraphicsGetImageFromCurrentImageContext() 

    UIGraphicsEndImageContext() 
} 

} 좋은 조치

답변

0
  1. , 당신의 다시 실행 버튼이 제대로 인터페이스 빌더에 설정되어 있는지 확인하고, 즉, 트리거하여 redoDraving 방법.

  2. 나는 같은 문제가 발생했습니다 (재실행 없음). This answer 나를 도왔습니다.