[Ios]scrollview for Mobile and zoom

Source: Internet
Author: User

Implement sliding

1. Assign a value to ScrollView's Contentsize property in Viewdidload to tell him the sliding range.

Implementing scaling

1. Set the zoom range in the Attribute tab of the storyboard ScrollView.

2. Implement a Uiscrollviewdelegate[scrollview delegate] and pass it to the ScrollView in Viewdidload

3. Implement uiscrollviewdelegate need to make a carbon copy-(UIView *) Viewforzoominginscrollview: (uiscrollview *) ScrollView

This method returns the view that needs zoom.

Note: If you use zoom and zoom view larger than the screen

You must set the Fram of the view that you want to zoom otherwise the zoom process will change the frame of the view to change to the size of the image causing the ScrollView contentsize change to affect the sliding effect.

So each time you use zoom you need to change the view to set its Frame.szie with its content size binding [like ImageView's image.size]

Brief code:

OC Code
  1. //
  2. Isviewcontroller.m
  3. Imageinscrollview
  4. //
  5. Created by Liu Poolo on 12-10-12.
  6. Copyright (c) 2012 Liu Poolo.  All rights reserved.
  7. //
  8. #import "ISViewController.h"
  9. @interface Isviewcontroller () <UIScrollViewDelegate>
  10. @end
  11. @implementation Isviewcontroller
  12. @synthesize Scrollview=_scrollview;
  13. @synthesize Imageview=_imageview;
  14. -(void) viewdidload
  15. {
  16. [Super Viewdidload];
  17. Set Uiscrollviewdelegate
  18. self.scrollview.delegate=self;
  19. Self.scrollview.contentsize=self.imageview.image.size;
  20. Self.imageview.frame=cgrectmake (0, 0, Self.imageView.image.size.width, self.imageView.image.size.height);
  21. Self.imageview.frame=cgrectmake (0, 0, Self.imageView.image.size.width, self.imageView.image.size.height);
  22. If I don't add this sentence,
  23. Then normal drag is OK, but if zoom is a problem
  24. Zoom will change frame to the current display size [imageview default size screen size as full screen is full screen size] Zoom change causes frame synchronization to alter the size of the image to frame size
  25. The size of the image changes to cause the self.scrollView.contentSize to become a frame and the contentsize becomes smaller and cannot be dragged properly.
  26. Then change according to zoom zoom scale. Instead of depending on the actual picture size. This causes zoom to be unable to drag [because frame size]
  27. }
  28. -(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView
  29. Returns the view that needs zoom
  30. {
  31. If you want ScrollView to implement scaling, you need to give Scrollview.delegate a Uiscrollviewdelegate object
  32. And this object needs to overwrite the Viewforzoominginscrollview method.
  33. Summary: Only ScrollView delegate carbon Viewforzoominginscrollview ScrollView will be scaled.
  34. return self.imageview;
  35. }
  36. -(void) didreceivememorywarning
  37. {
  38. [Super didreceivememorywarning];
  39. Self.scrollview=nil;
  40. Self.imageview=nil;
  41. }
  42. @end

[Ios]scrollview for Mobile and zoom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.