[IPhone application development] iPhone application development 5: uiscrollview

Source: Internet
Author: User

Today we will talk about some things of uiscrollview. This drag-and-drop component is often used in both application and game development, so we must be more familiar with it. Let's get started.

(1) initialization

Generally, you can use alloc and init to initialize components.CodeInitialization.

 
Uiscrollview * SV = [[uiscrollview alloc] initwithframe: cgrectmake (0.0, 0.0, self. View. Frame. Size. Width, 400)];

 

 

There are also many methods for initialization. You can determine the frame of the component or some attributes. For example, the type of the button can be determined by uibutton initialization. Of course, I strongly recommend that you use code for writing. This gives you a better understanding of the entire code execution process, rather than using IB for layout. Indeed, many people use IB for layout, which saves a lot of time, however, this varies from person to person, And I advocate pure code writing.

 

(2) rolling attributes

The biggest attribute of uiscrollview is that it can be rolled, which looks good. In fact, the main principle of the rolling effect is to modify the coordinates of the original point, uiscrollview is the same as other components and has its own delegate. in the H file, inherit the delegate of uiscrollview and. the delegate set for viewdidload of the M file is self. As follows:

 
Sv. pagingenabled = yes; Sv. backgroundcolor = [uicolor bluecolor]; Sv. showsverticalscrollindicator = no; Sv. showshorizontalscrollindicator = no; Sv. delegate = self; cgsize newsize = cgsizemake (self. view. frame. size. width * 2, self. view. frame. size. height); [SV setcontentsize: newsize]; [self. view addsubview: Sv];


 

In the above Code, you must set the pagingenable of uiscrollview to yes. Otherwise, you just set other attributes, and it still cannot be dragged. Next, you will set the background color and whether to display the horizontal and vertical drag bars. Finally, the most important thing is to set its contentsize, contentsize indicates the size of all its content. This is different from its frame, and only the contentsize is greaterFrameIn this way, drag is supported.

 

(3) combined with uipagecontrol for news page turning

The method for initializing uipagecontrol is very simple, that is, the alloc and init mentioned above. But remember that if you define global variables, you must release them in delloc.

 

Uipagecontrol has a userinteractionenabled which you can set to No. It does not call any method when you click. Set its currentpage to 0 and add it to the view.

 

The delegate method of uiscrollview is as follows:

 
-(Void) scrollviewdidscroll :( uiscrollview *) scrollview;

 

Here you can write about the uipagecontrol page settingsAlgorithm. As follows:

 

Int Index = FABS (scrollview. contentoffset. X)/scrollview. Frame. Size. width; pagecontrol. currentpage = index;

 

(4) Other

Uiscrollview also supports scaling down or map.

However, you must implement its delegate viewforzoominginscrollview:
Scrollviewdidendzooming: withview: atscale: The two attributes of maximumzoomscale are different from those of minimumzoomscale. In this way, the image can be scaled.

 

Now, we will talk about uiscrollview and uipagecontrol here. I hope everyone can understand it. Welcome to shoot bricks.

Add a photo using uiscrollview implementation demo for everyone: http://files.cnblogs.com/huangdongcheng/PagePhotosDemo.zip

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.