我使用简单图像添加了旋转和捏合手势识别器(从对象库中添加)。我使用了2条带有2个IBAction的基本简单线来旋转和缩放图像。一切正常,但问题是:每个手势重置另一个值。如果我旋转图像并在我进行捏合后,旋转值将恢复正常,反之亦然。我想保留旋转和缩放的值。我希望清楚这个问题。谢谢大家。这里是代码:
// ImageController.swift
// SpImage
//
// Created by Ronny Westwood on 06/09/17.
// Copyright © 2017 RW2017. All rights reserved.
//
import UIKit
class ImageController: UIViewController {
@IBOutlet weak var Image: UIImageView!
/// IMAGE OUTLET
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func rotationImage(_ sender: UIRotationGestureRecognizer) {
Image.transform = view.transform.rotated(by: sender.rotation)
}
@IBAction func zoomImage(_ sender: UIPinchGestureRecognizer) {
Image.transform = CGAffineTransform(scaleX: sender.scale, y: sender.scale)
}
/// IMAGE ROTATION & IMAGE ZOOM
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
这里的观点: View
答案 0 :(得分:1)
我用这段代码解决了这个问题。一切正常
class ImageController: UIViewController, UIGestureRecognizerDelegate {
var delegate: UIGestureRecognizerDelegate?
@IBOutlet weak var Image: UIImageView!
override func viewDidLoad()
{
super.viewDidLoad()
}
@IBAction func rotationImage(_ gestureRecognizer : UIRotationGestureRecognizer)
{
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed
{
gestureRecognizer.view?.transform = (gestureRecognizer.view?.transform.rotated(by: gestureRecognizer.rotation))!
gestureRecognizer.rotation = 0.0;
}
}
@IBAction func zoomImage(_ gestureRecognizer : UIPinchGestureRecognizer)
{
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed
{
gestureRecognizer.view?.transform = (gestureRecognizer.view?.transform.scaledBy(x: gestureRecognizer.scale, y: gestureRecognizer.scale))!
gestureRecognizer.scale = 1.0;
}
}
/// IMAGE ROTATION & IMAGE SCALE
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool
{
return true
}
/// ALLOW SIMULTANEOUS GESTURES DELEGATE
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
}
(是的,是AppleDeveloper关于GestureRecognizer的代码) 谢谢所有人。 代码上的另一块砖。