我已经迅速发布了iOS应用,其主要功能是:
1)添加照片/拍照
2)在照片上添加表情符号
3)缩放,旋转,拖动表情符号来装饰照片
4)在Instagram上分享。
表情符号可以旋转,缩放和拖动。我已使用UIRoationGestrueRecognizer,UIPinchGestureRecognizer和UIPanGesstureRecognizer等UIGestureRecognizers实现了这些功能。
现在,我正在尝试使用类似手套的缩小缩放功能来更新应用程序,用户可以将两个手指之间的表情符号放大/缩小到最大程度。当前的捏合手势仅在用户的手指位于imageView(表情符号)上时有效。
任何想法/示例代码如何进行类似手套的捏缩放?下面的代码是我处理旋转,收缩和拖动的方式。提前致谢。
// UI Gesture Recognizers
@IBAction func handlePinch(recognizer : UIPinchGestureRecognizer) {
if(deleteMode) {
return
}
if let view = recognizer.view {
view.transform = CGAffineTransformScale(view.transform,
recognizer.scale, recognizer.scale)
recognizer.scale = 1
}
}
@IBAction func handleRotate(recognizer : UIRotationGestureRecognizer) {
if(deleteMode) {
return
}
if let view = recognizer.view {
view.transform = CGAffineTransformRotate(view.transform, recognizer.rotation)
recognizer.rotation = 0
}
}
@IBAction func handlePan(recognizer:UIPanGestureRecognizer) {
if(deleteMode) {
return
}
let translation = recognizer.translationInView(self.view)
var centerX: CGFloat!
var centerY: CGFloat!
if let view = recognizer.view {
// limit the boundary - using backgroundPanel.frame.width, height, origin.x, origin.y
if(view.center.x + translation.x < panelBackground.frame.origin.x) {
centerX = view.center.x + translation.x + 10
} else if(view.center.x > panelBackground.frame.size.width){
centerX = view.center.x + translation.x - 10
} else {
centerX = view.center.x + translation.x
}
if(view.center.y < panelBackground.frame.origin.y - 60){
// set y that I can use below
centerY = view.center.y + translation.y + 10
} else if(view.center.y > panelBackground.frame.size.height){
centerY = view.center.y + translation.y - 10
} else {
centerY = view.center.y + translation.y
}
// set final position
view.center = CGPoint(x:centerX,
y:centerY)
recognizer.setTranslation(CGPointZero, inView: self.view)
}
}
@IBAction func handleLongPress(recognizer: UILongPressGestureRecognizer) {
if(recognizer.state == UIGestureRecognizerState.Began) {
if(!deleteMode) {
print("LongPress - Delete Shows")
for (_, stickers) in self.backgroundImage.subviews.enumerate() {
for (_, deleteButtons) in stickers.subviews.enumerate() {
if let delete:UIImageView = deleteButtons as? UIImageView{
if(delete.accessibilityIdentifier == "delete") {
delete.alpha = 0.5
}
}
}
}
deleteMode = true
} else {
deleteButtonHides()
}
}
}
最佳答案
我也希望同时进行拖拉,平移和缩放,例如手套,但是如果您只是在寻找缩放。我正在使用下面的功能通过捏捏来缩放标签。它不是很平滑,但是可以进行缩放。
func handlePinch(recognizer: UIPinchGestureRecognizer) {
if let view = recognizer.view as? UILabel {
let pinchScale: CGFloat = recognizer.scale
view.transform = view.transform.scaledBy(x: pinchScale, y: pinchScale)
recognizer.scale = 1.0
}
}
要同时进行拖动,平移和缩放,请查看以下文章:
Pinch, drag and pan at the same time
关于ios - 在iOS上像手套一样捏放大,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35756473/