如何将 UIPinchGestureRecognizer 与整个视图一起使用以缩放整个屏幕? Swift3、IOS
How can I use the UIPinchGestureRecognizer with the entire view to zoom the entire screen? Swift 3, IOS
我似乎无法将我的动作(捏合手势)连接到我的视图,而是连接到 viewcontroller。这是我在视图控制器中编写的所有代码以测试代码:
import UIKit
class AlertController: UIAlertController {
@IBAction func scaleImage(sender: UIPinchGestureRecognizer) {
self.view.transform = CGAffineTransformScale(self.view.transform, sender.scale, sender.scale)
sender.scale = 1
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view.backgroundColor = UIColor.blackColor()
}
override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning()
}
}
我只想放大我在我的应用程序中填写的表单(文本框 - 按钮和标签,复选框 - 按钮和标签,背景图像 - 图像视图)。我希望能够一次放大所有内容。我失败得很惨。请帮忙! :)
首先制作识别器:
let pinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(pinchHandler))
然后创建处理函数:
func pinchHandler(recognizer : UIPinchGestureRecognizer) {
print ("PINCHING NOW")
if let view = self.view {
view.transform = view.transform.scaledBy(x: recognizer.scale, y: recognizer.scale)
recognizer.scale = 1
}
}
在 viewDidLoad 中添加识别器:
pinchGestureRecognizer.addTarget(self, action: #selector(pinchHandler))
view.addGestureRecognizer(pinchGestureRecognizer)
我似乎无法将我的动作(捏合手势)连接到我的视图,而是连接到 viewcontroller。这是我在视图控制器中编写的所有代码以测试代码:
import UIKit
class AlertController: UIAlertController {
@IBAction func scaleImage(sender: UIPinchGestureRecognizer) {
self.view.transform = CGAffineTransformScale(self.view.transform, sender.scale, sender.scale)
sender.scale = 1
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view.backgroundColor = UIColor.blackColor()
}
override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning()
}
}
我只想放大我在我的应用程序中填写的表单(文本框 - 按钮和标签,复选框 - 按钮和标签,背景图像 - 图像视图)。我希望能够一次放大所有内容。我失败得很惨。请帮忙! :)
首先制作识别器:
let pinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(pinchHandler))
然后创建处理函数:
func pinchHandler(recognizer : UIPinchGestureRecognizer) {
print ("PINCHING NOW")
if let view = self.view {
view.transform = view.transform.scaledBy(x: recognizer.scale, y: recognizer.scale)
recognizer.scale = 1
}
}
在 viewDidLoad 中添加识别器:
pinchGestureRecognizer.addTarget(self, action: #selector(pinchHandler))
view.addGestureRecognizer(pinchGestureRecognizer)