iOS development, using Uiscrollview and timers to implement an auto-infinite scrolling banner (of course, touch-drag is also supported)

Source: Internet
Author: User

First of all, we know that the ScrollView has the Contentsize attribute, set to drag, set this property to 3 Imagevie width.

When the initialization is displayed, the direct setting of the contentsize is displayed in the position of the second ImageView, in the ScrollView proxy method, we can determine the value of the contentoffset.x, if the decrease is dragged to the left, and if it is increased, drag to the right.

If you drag to the left for 0 to finish, if twice times the width of the imgaeview represents the right drag to finish, when drag is done by default the last ImageView image of the direction of movement is set to the middle of the ImageView, Set the last ImageView image to nil, the middle of the ImageView Imgae move forward one step, the opposite direction is the same, set up, directly set ScrollView Contentoffset for the second ImageView position, After setting, you will not see a noticeable animation, which will force the scrolling view to be reset by the original parameters.

Timer function: When the picture starts to drag, the timer count variable resets to 0, when the timer count variable reaches a certain value, this time call ScrollView direction, set Contentoffset animation method to the right to slide a imageview width, The drag method in the proxy method is invoked for position and fixup parameters

The code is attached later, small dots add just a friendly hint, in fact very simple

iOS development, using Uiscrollview and timers to implement an auto-infinite scrolling banner (of course, touch-drag is also supported)

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.