2

I want to apply pinch-in and pinch-out gesture into a imageView in my application.

I am using Xcode9 and swift 3.2

I could not able to tap on specific two coordinate at a time of my desired image

app.scrollViews.scrollViews.images.element(boundBy: 0)
Mimu Saha Tishan
  • 2,402
  • 1
  • 21
  • 40

2 Answers2

4

For zoom in or zoom out you have to use pinch(withScale:velocity:) method of xctest.

Your code should look like below

let image = app.scrollViews.scrollViews.images.element(boundBy: 0)

Zoom in:

image.pinch(withScale: 3, velocity: 1) // zoom in

Zoom out:

image.pinch(withScale: 0.5, velocity: -1) // zoom out

According to api documentation of pinch(withScale:velocity:) negative velocity is for zoom out and positive velocity is for zoom in

Please use the above code and let me know your feedback.

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
Mahmud Riad
  • 1,169
  • 1
  • 8
  • 19
0

Use pinch(withScale:velocity:) on your image element.

let image = app.scrollViews.scrollViews.images.element(boundBy: 0)
image.pinch(withScale: 3, velocity: 1) // zoom in
image.pinch(withScale: 0.5, velocity: -1) // zoom out
Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
Oletha
  • 7,324
  • 1
  • 26
  • 46
  • Thanks @Oletha, for your feedback. I have tried with your code, zoom in working perfectly but zoom out not worked well. I have tried with different values and ways also but it is not working for me. Would u plz provide how this working for U. – Mimu Saha Tishan Jan 03 '18 at 14:03
  • I'm not actually using this API in my project, I'm just going off the documentation linked above. After zooming in a lot, the scale for zooming back out potentially needs to be very small. – Oletha Jan 03 '18 at 14:05
  • According to your provided value, zoom out not working – Mimu Saha Tishan Jan 30 '18 at 15:08
  • Did you try with a negative value? – Oletha Jan 30 '18 at 15:11
  • scale can not be negative according to api documentation. – Mahmud Riad Jan 30 '18 at 15:16
  • Ok, try the same scale with the inverse velocity. Thanks @MahmudRiad for pointing out the velocity can be negative. That makes sense since velocity has direction as well as speed. – Oletha Jan 30 '18 at 15:19
  • 1
    Apple Docs say "The scale of the pinch gesture. Use a scale between 0 and 1 to "pinch close" or zoom out" – DBD Aug 31 '20 at 13:19