Paging and scaling of Uiscrollview in iOS

Source: Internet
Author: User

The Uiscrollview class provides support for displaying the view size of content larger than the application window. It enables users to scroll through the content in a light sweep gesture, zooming in and out of the view by hand-pinching gestures.

Paging

When there are multiple views in the frame, you do not want to drag the interface to stop in the middle of the connection position, you need paging function

CGRect screenrect = 

[Self.window bounds];  
CGRect bigrect = screenrect;  
BigRect.size.width *= 2.0;  
      
Initialize ScrollView  
Uiscrollview *scrollview = [Uiscrollview alloc] initwithframe:screenrect];  
[Self.window Addsubview:scrollview];  
      
Creates a custom view object and adds it to the ScrollView  
myview *view = [MyView alloc] initwithframe:screenrect];  
[ScrollView Addsubview:view];  
      
Creates another object that is just outside the screen, screenrect.origin.x = screenRect.size.width on the right side of the previous view  
;  
MyView *anotherview = [MyView alloc] initwithframe:screenrect];  
[ScrollView Addsubview:anotherview];

Complete the basic settings, there are two properties in the Uiscrollview, Contentsize and Pagingenabled, the former determines the scope of the Uiscrollview, the latter is to set whether the system automatically paging

[ScrollView setContentSize:bigRect.size];  
[ScrollView Setpagingenabled:yes];

Scaling

Assuming you have a view member in this application, you want to achieve his zoom out function

CGRect screenrect = [Self.window bounds];  
      
Initialize the ScrollView and set its zoom scale to implement the delegate  
uiscrollview *scrollview = [Uiscrollview alloc] initwithframe:screenrect];  
      
[ScrollView setminimumzoomscale:1.0];  
[ScrollView setmaximumzoomscale:5.0];  
      
[ScrollView setdelegate:self];  
      
[Self.window Addsubview:scrollview];  
      
Initialize member  
MyView = [MyView alloc] initwithframe:screenrect];

For this scrolling view to implement scaling, you need to adhere to the Uiscrollviewdelegate protocol, and then implement the Delegate method

-(UIView *)

Viewforzoominginscrollview: (Uiscrollview *) ScrollView  
{return  
   myview;  
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Related Article

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.