图像上类似Snapchat的文字 [英] Snapchat-like text on image
问题描述
我一直在尝试在图像上实现类似Snapchat的编辑文本。
我到目前为止所做的是在UIImageView的中心实现一个UILabel,我为这个UILabel增加了3个手势:UIPanGestureRecognizer,UIPinchGestureRecognizer& UIRotationGestureRecognizer。
我已经设法实现了Pan方法,但是我很难让Pinch + Rotation像他们一样平滑,我得到了可怕的结果T_T
你们怎么看待这个?哪个组件涉及此&如果你有任何阅读/观看材料,我可以用它来完成这个。
谢谢:)
编辑:
这些是我实施的处理Pinch& amp;的方法。轮换:
func handlePinch(识别器:UIPinchGestureRecognizer){
如果让view = recognizer.view为? UILabel {
view.transform = CGAffineTransformScale(view.transform,recognizer.scale,recognizer.scale)
}
}
func handleRotate(识别器:UIRotationGestureRecognizer){如果让view = recognizer.view为
? UILabel {
view.transform = CGAffineTransformRotate(view.transform,recognizer.rotation)
}
}
预览我实施的捏合工作的视频:
找到一个解决方案,显然我需要做的就是旋转&捏合始终重置视图的旋转/比例。
例如,将我的Recognizer.scale设置为1.0并将recognizer.rotation设置为0.0。
以下是我的代码示例:
func handlePan(识别器: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(识别器:UIPinchGestureRecognizer){
如果让view = recognizer.view为? UILabel {
let pinchScale:CGFloat = recognizer.scale
view.transform = CGAffineTransformScale(view.transform,pinchScale,pinchScale)
recognizer.scale = 1.0
}
}
func handleRotate(识别器:UIRotationGestureRecognizer){
如果让view = recognizer.view为? UILabel {
让旋转:CGFloat = recognizer.rotation
view.transform = CGAffineTransformRotate(view.transform,rotation)
recognizer.rotation = 0.0
}
}
I have been trying to implement a Snapchat-like edit text on an image. What I did so far is implement a UILabel in the center of the UIImageView and I added 3 gestures to this UILabel: UIPanGestureRecognizer, UIPinchGestureRecognizer & UIRotationGestureRecognizer.
I have managed to implement the Pan method, but I am having hard time to make the Pinch + Rotation as smooth as they do, I get horrible results T_T
How do you guys think this was made? which components are involved in this & if you have any reading / watching material I could use to accomplish this.
Thanks :)
EDIT:
These are the methods I implemented to handle Pinch & Rotation:
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)
}
}
Preview video of how the pinch I implemented works: https://drive.google.com/file/d/0B-AVM51jxsvUY2RUUHdWbGo5QlU/view?usp=sharing
Found a solution, apparently all I needed to do in the Rotation & Pinch is to always reset the view's rotation / scale. For instance, setting my recognizer.scale to 1.0 and recognizer.rotation to 0.0.
Here is an example of my code:
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
}
}
这篇关于图像上类似Snapchat的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!