小编Kas*_*245的帖子

在做手势时将锚点放在屏幕的中心

我有一个图像,可以响应捏,旋转和平移手势.我希望图像的捏合和旋转将相对于放置在屏幕中间的锚点完成,就像使用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)

xcode calayer ios swift

9
推荐指数
1
解决办法
786
查看次数

标签 统计

calayer ×1

ios ×1

swift ×1

xcode ×1