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.


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];


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  

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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.