How to use OnViewForZoomingInScrollView

Hi,

I would like to let the user zoom an image within a ScrollView. What is the suggested way to do this?
How is the ViewForZoomingInScrollView used?

Thank you,
Michael

Hi, 


You need set a TMSFMXNativeUIImageView as a child of a TTMSFMXNativeUIScrollView and then return the TMSFMXNativeUIImage as the View parameter of the ViewForZoomingInScrollView.

Afterwards, set the MinimumZoomScale to 1 and MaximumZoomScale to 5

  TMSFMXNativeUIScrollView1.ScrollView.setZoomScale(1);
  TMSFMXNativeUIScrollView1.ScrollView.setMinimumZoomScale(1);
  TMSFMXNativeUIScrollView1.ScrollView.setMaximumZoomScale(5);

Set the contentmode of the image view to aspect fit.

procedure TForm1.TMSFMXNativeUIScrollView1ViewForZoomingInScrollView(
  Sender: TObject; var AView: TTMSFMXNativeUIBaseControl);
begin
  AView := TMSFMXNativeUIImageView1;
end;

The minimumzoomscale is 1 which is the original size of the image, if you wish that the image takes the full size of the scrollview, then you need to set the width and height of the ImageView to the size of the ScrollView. You need to experiment with these properties until you get the desired effect.

if you have difficulties with this, please remind me on Monday so I can provide you with a sample.


Kind Regards, 
Pieter

Hi Pieter,

this work perfect - thank you!

I have two further questions to zooming:

  1. Can I change the zooming to any kind of vertical or "horizontal scaling? I would like to stick the width on a fixed size and let the height scale. (Or vice versa)
  2. How can I get an event which notifies me when the user ends the scaling process?

BTW: It is real fun creating real native apps for iOS with your components! The native components are incredibly fast.


Best regards,
Michael

Hi, 


The native components are indeed very fast, which is kind of expected when using a native approach. There is an didEndZooming delegate call but it is not implemented currently. This is also due to the implementation of iOSApi.UIKit which is provided by Embarcadero in XE4. Perhaps you could take a look at the documentation of the UIScrollView:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html

If there is something you are missing then we will provide it in an update.
After a quick search it seems quite difficult to lock zooming to vertical or horizontal scaling, it needs an override of the setTransform on UIScrollView, this is something that is currently not possible.

A tip that can be helpful, you can also search directly on UIScrollView, or any other native UI control in google, with the feature or implementation you are looking for, as the wrappers have access to the native UI controls so it is only a matter of translating the code that you have found in ObjectiveC to Delphi.

Kind Regards, 
Pieter


Pieter Scheldeman2013-07-13 07:35:43

Hello Pieter,

I extended the delegate of your ScrollView implementation and I now can recieve the missing events.
If you like, I can provide the modifications to you. Were can I send them to?

Regarding the scaling I will do some further research.

Best regards,
Michael


Hi,



You can send them to support@tmssoftware.com and a link to this post.

We will try to include it in the next small update.



Kind Regards,

Scheldeman Pieter