我已经创建了一个图形与核心情节,并试图使用捏缩放功能。我希望夹子只在x轴或者y轴上工作。我使用下面的代码实现了这一点,在我输入的捏手势识别器中使用了以下代码。
- (void)handlePinch:(UIPinchGestureRecognizer*)recognizer
{
//NSLog(@"We are pinching");
//This allows you to figure out which direction the pinch is occuring HORIZ or VERT
if (recognizer.state != UIGestureRecog
我希望允许用户在SwiftUI中对图像进行缩小放大。我认为最好的方法是使用MagnificationGesture,然后,在回答之后,我得到了以下代码:
// outside of `var body: some View`
@State private var scale: Int = 1.0
@State private var lastScale: Int = 1.0
// Image
Image("dog")
.resizable()
.aspectRatio(contentMode: .fit)
.gesture(MagnificationGesture()