我有一个图像,可以响应捏,旋转和平移手势.我希望图像的捏合和旋转将相对于放置在屏幕中间的锚点完成,就像使用Xcode iPhone模拟器按下选项键一样.如果图像的中心可能会缩放并平移到其他位置,如何将锚点放在屏幕中间?
这是我的缩放和旋转手势功能:
@IBAction func pinchGesture(_ gestureRecognizer: UIPinchGestureRecognizer) {
// Move the achor point of the view's layer to the touch point
// so that scaling the view and the layer becames simpler.
self.adjustAnchorPoint(gestureRecognizer: gestureRecognizer)
// Scale the view by the current scale factor.
if(gestureRecognizer.state == .began) {
// Reset the last scale, necessary if there are multiple objects with different scales
lastScale = gestureRecognizer.scale
}
if (gestureRecognizer.state == .began || gestureRecognizer.state == .changed) {
let currentScale = gestureRecognizer.view!.layer.value(forKeyPath:"transform.scale")! as! …Run Code Online (Sandbox Code Playgroud)