ios – 图像上类似Snapchat的文本

前端之家收集整理的这篇文章主要介绍了ios – 图像上类似Snapchat的文本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在尝试在图像上实现类似Snapchat的编辑文本.
我到目前为止所做的是在UI ImageView的中心实现UILabel,我在这个UILabel中添加了3个手势:UIPanGestureRecognizer,UIPinchGestureRecognizer& UIRotationGestureRecognizer.

我已经设法实现了Pan方法,但是我很难让Pinch Rotation像他们一样平滑,我得到了可怕的结果T_T

你们怎么看待这个?哪个组件涉及此&如果你有任何阅读/观看材料我可以用来完成这个.

谢谢 :)

编辑:

这些是我实施的处理Pinch& amp;的方法.回转:

func handlePinch(recognizer: UIPinchGestureRecognizer) {
    if let view = recognizer.view as? UILabel {
        view.transform = CGAffineTransformScale(view.transform,recognizer.scale,recognizer.scale)
    }
}

func handleRotate(recognizer: UIRotationGestureRecognizer) {
    if let view = recognizer.view as? UILabel {
        view.transform = CGAffineTransformRotate(view.transform,recognizer.rotation)
    }
}

预览我实施的夹点如何工作的视频:
https://drive.google.com/file/d/0B-AVM51jxsvUY2RUUHdWbGo5QlU/view?usp=sharing

解决方法

找到了一个解决方案,显然我只需要在Rotation&捏合始终重置视图的旋转/比例.
例如,将我的Recognizer.scale设置为1.0,将Recognizer.rotation设置为0.0.

这是我的代码示例:

func handlePan(recognizer: UIPanGestureRecognizer) {
    let translation = recognizer.translationInView(view)
    if let view = recognizer.view {
        view.center = CGPoint(x:view.center.x + translation.x,y:view.center.y + translation.y)
    }
    recognizer.setTranslation(CGPointZero,inView: view)
}

func handlePinch(recognizer: UIPinchGestureRecognizer) {
    if let view = recognizer.view as? UILabel {
        let pinchScale: CGFloat = recognizer.scale
        view.transform = CGAffineTransformScale(view.transform,pinchScale,pinchScale)
        recognizer.scale = 1.0
    }
}

func handleRotate(recognizer: UIRotationGestureRecognizer) {
    if let view = recognizer.view as? UILabel {
        let rotation: CGFloat = recognizer.rotation
        view.transform = CGAffineTransformRotate(view.transform,rotation)
        recognizer.rotation = 0.0
    }
}
原文链接:https://www.f2er.com/iOS/328504.html

猜你在找的iOS相关文章