Swift detailed 18------------ScrollView

Source: Internet
Author: User

ScrollView

注:本小节详细介绍scrollView的用法

Uiscrollview is a scroll-capable view control that can be used to display a large amount of content, and can be scrolled to see all the content
Uiscrollview usage, add the content you need to show to Uiscrollview
Set the Contentview property of the Uiscrollview to tell Uiscrollview the dimensions of all content

Let scroll =Uiscrollview(); Scroll. BackgroundColor=Uicolor. Graycolor() Scroll. Frame= CGRectMake (Ten, -, -, Max)//Set the size of the ScrollViewScroll. Contentsize= Cgsizemake ( -, Max)//Content sizeScroll. pagingenabled=true                 //Whether paging is supported        //scroll.contentoffset = cgpointmake (0, -10)Scroll. Contentinset=uiedgeinsets(Top:Ten, left:Ten, bottom:Ten, right:Ten)//inner marginLet ImageView =Uiimageview(Image:UIImage(named:"Dog1")) ImageView. Frame= CGRectMake (Ten,Ten, the, the) Scroll. Addsubview(imageView) Let ImageView1 =Uiimageview(Image:UIImage(named:"Dog2")) ImageView1. Frame= CGRectMake ( -+Ten,Ten, the, the) Scroll. Addsubview(imageView1) Let imageView2 =Uiimageview(Image:UIImage(named:"Dog3")) ImageView2. Frame= CGRectMake ( -*2+Ten,Ten, the, the) Scroll. Addsubview(IMAGEVIEW2) Let imageView3 =Uiimageview(Image:UIImage(named:"Dog4")) IMAGEVIEW3. Frame= CGRectMake ( -*3+Ten,Ten, the, the) Scroll. Addsubview(IMAGEVIEW3) Self. View. Addsubview(scroll)

Here I created a scrollview and set some properties (all commented), and then added a picture of four puppies. The effect is the horizontal drag to rotate the display of four pictures


Swipe to rotate

A scalable example is described below

Let ScrollView = Uiscrollview ();ScrollView. Frame= CGRectMake (Ten, $, viewwidth- -, -) ScrollView. BackgroundColor= Uicolor. Purplecolor() ScrollView. Contentinset= Uiedgeinsets (top:Ten, left:0, bottom:0, right:0) ImageView4 = Uiimageview (Image:uiimage (named:"Pic1")) imageview4!. Frame= CGRectMake (0,Ten, viewwidth- -,280) ScrollView. Addsubview(imageview4!) ScrollView. Contentsize=cgsizemake (viewwidth- -, -);ScrollView. Maximumzoomscale=2.0;//Set maximum scaling ratioScrollView. Minimumzoomscale=0.5;//Set minimum scaling ratio

Also set some basic properties and then set the scaling scale

    class ViewController: UIViewController , UIScrollViewDelegate

Let our controller implement uiscrollviewdelegate this Protocol

 scrollview.delegateself

Set the ScrollView proxy as the current object

  //告诉scrollview要缩放的是哪个子控件    UIScrollViewUIView? {        return imageView4    }

Then implement this method to tell ScrollView which child control to scale
Run to see if you can actually zoom in.

Here's a look at some of the other events in Uiscrollviewdelegate

FuncScrollviewdidscroll (Scrollview:uiscrollview){print ("Whenever you scroll, it triggers.") ")} funcscrollviewwillbegindragging (Scrollview:uiscrollview){print ("Start dragging View")} funcscrollviewdidenddragging (Scrollview:uiscrollview, willdecelerate decelerate:bool){print ("End scrolling")} funcscrollviewwillbegindecelerating (Scrollview:uiscrollview){print ("will start to spin down")} funcscrollviewdidenddecelerating (Scrollview:uiscrollview){print ("execution when deceleration is stopped, execution on hand touch")} funcscrollviewdidendscrollinganimation (Scrollview:uiscrollview){print ("execution when scrolling animation stops, trigger when code changes, i.e. Setcontentoffset changes")} funcscrollviewdidendzooming (Scrollview:uiscrollview, Withview view:uiview?, Atscale scale:cgfloat){print (called when Zoom Out is complete)}

It's clearly documented when it's done. It's clear that we can try

Finally, we enclose the source code for these examples (this example is implemented on Xcode 7 Beta): ScrollView

All submitted the discovery also less what, originally less this figure. (This image is from the network)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Swift detailed 18------------ScrollView

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.