撤消/重做图像进度
我有一个更改图片的功能,并且有两个取消/返回按钮 我为此写了3个功能 添加 撤消 重做 问题是,当我按2次撤消然后重做时,我的图像重做是两个步骤向前
我的代码
public var undoHistory: [UIImage] = []
public var redoHistory: [UIImage] = []
public func undoImage() -> UIImage? {
guard !(undoHistory.count == 1) else {
return undoHistory.last
}
if let lastImage = undoHistory.last {
redoHistory.append(lastImage)
undoHistory.removeLast()
}
return undoHistory.last
}
public func addImageToHistory(_ image: UIImage) {
undoHistory.append(image)
guard !redoHistory.isEmpty else {
return
}
redoHistory.removeAll()
}
public func redoImage() -> UIImage? {
guard !(redoHistory.count == 1) else {
return redoHistory.last
}
if let lastImage = redoHistory.last {
redoHistory.removeLast()
undoHistory.append(lastImage)
}
return redoHistory.last
}
I have a functionality that changes the picture, and there are two cancel/return buttons
i wrote 3 functions for this
add
undo
redo
The problem is that when I press 2 times undo and then redo, my image redo is two steps forward
My code
public var undoHistory: [UIImage] = []
public var redoHistory: [UIImage] = []
public func undoImage() -> UIImage? {
guard !(undoHistory.count == 1) else {
return undoHistory.last
}
if let lastImage = undoHistory.last {
redoHistory.append(lastImage)
undoHistory.removeLast()
}
return undoHistory.last
}
public func addImageToHistory(_ image: UIImage) {
undoHistory.append(image)
guard !redoHistory.isEmpty else {
return
}
redoHistory.removeAll()
}
public func redoImage() -> UIImage? {
guard !(redoHistory.count == 1) else {
return redoHistory.last
}
if let lastImage = redoHistory.last {
redoHistory.removeLast()
undoHistory.append(lastImage)
}
return redoHistory.last
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论