IOS about Auto-carousel Pictures

Source: Internet
Author: User
<span id="Label3"></p><pre> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Initialize the current view</span></span>_currentimageview =<span style="color: #000000;"><span style="color: #000000;">[[uiimageview alloc] init]; [_currentimageview Setimagewithurl:[nsurl urlwithstring:[array_pic objectatindex:</span></span><span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">]]]; _currentimageview.frame</span></span>= CGRectMake (myScroller.frame.size.width,<span style="color: #800080;"><span style="color: #800080;">0</span></span>, myScroller.frame.size.width,<span style="color: #800080;"><span style="color: #800080;"></span> the</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">_currentimageview.contentmode = uiviewcontentmodescaleaspectfill;</span></span><span style="color: #000000;"><span style="color: #000000;">[myscroller addsubview:_currentimageview]; _nextimageview</span></span>=<span style="color: #000000;"><span style="color: #000000;">[[uiimageview alloc] init]; [_nextimageview Setimagewithurl:[nsurl urlwithstring:[array_pic objectatindex:</span></span><span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">]]]; _nextimageview.frame</span></span>= CGRectMake (myScroller.frame.size.width *<span style="color: #800080;"><span style="color: #800080;">2</span></span>,<span style="color: #800080;"><span style="color: #800080;">0</span></span>, myScroller.frame.size.width,<span style="color: #800080;"><span style="color: #800080;"></span> the</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">_nextimageview.contentmode = uiviewcontentmodescaleaspectfill;</span></span><span style="color: #000000;"><span style="color: #000000;">[myscroller addsubview:_nextimageview]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Initialize the previous view</span></span>_previousview =<span style="color: #000000;"><span style="color: #000000;">[[uiimageview alloc] init]; [_previousview Setimagewithurl:[nsurl urlwithstring:[array_pic objectatindex:</span></span><span style="color: #800080;"><span style="color: #800080;">3</span></span><span style="color: #000000;"><span style="color: #000000;">]]]; _previousview.frame</span></span>= CGRectMake (<span style="color: #800080;"><span style="color: #800080;">0</span></span>,<span style="color: #800080;"><span style="color: #800080;">0</span></span>, myScroller.frame.size.width,<span style="color: #800080;"><span style="color: #800080;"></span> the</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">_previousview.contentmode = uiviewcontentmodescaleaspectfill;</span></span><span style="color: #000000;"><span style="color: #000000;">[myscroller addsubview:_previousview]; } {smpagecontrol</span></span>*pagecontrol =<span style="color: #000000;"><span style="color: #000000;">[[smpagecontrol alloc] init]; [pagecontrol Setframe:cgrectmake (</span></span><span style="color: #800080;"><span style="color: #800080;">0</span></span>, myscroller.frame.size.height+<span style="color: #800080;"><span style="color: #800080;"></span> -</span>-<span style="color: #800080;"><span style="color: #800080;">10.0f</span></span>, myScroller.frame.size.width,<span style="color: #800080;"><span style="color: #800080;">10.0f</span></span><span style="color: #000000;"><span style="color: #000000;">)]; [pagecontrol setnumberofpages:</span></span><span style="color: #800080;"><span style="color: #800080;">4</span></span><span style="color: #000000;"><span style="color: #000000;">]; [pagecontrol Setbackgroundcolor:[uicolor clearcolor]; [pagecontrol setcurrentpage:</span></span><span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">]; [pagecontrol Setcurrentpageindicatortintcolor:[uicolor lightgraycolor]; [pagecontrol Setpageindicatortintcolor:[uicolor graycolor]; Mypagecontrol</span></span>=<span style="color: #000000;"><span style="color: #000000;">pagecontrol; [self.view addsubview:mypagecontrol]; }</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(!<span style="color: #000000;"><span style="color: #000000;">[mytimer IsValid]) {mytimer</span></span>=[nstimer Scheduledtimerwithtimeinterval:<span style="color: #800080;"><span style="color: #800080;">5</span></span><span style="color: #000000;"><span style="color: #000000;">target:self selector: @selector (updateauto) userinfo:nil repeats:yes]; }</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">#pragma</span></span>Mark Clock Animation call method-(<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) updateauto{</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(_isdraging) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">; } cgpoint offset</span></span>=<span style="color: #000000;"><span style="color: #000000;">myscroller.contentoffset; Offset.x</span></span>+=<span style="color: #000000;"><span style="color: #000000;">self.view.frame.size.width; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(offset.x > self.view.frame.size.width*<span style="color: #800080;"><span style="color: #800080;">2</span></span><span style="color: #000000;"><span style="color: #000000;">) {offset.x</span></span>=<span style="color: #000000;"><span style="color: #000000;">self.view.frame.size.width; } [myscroller setcontentoffset:offset animated:yes];}</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">#pragma</span></span>Mark-proxy method<span style="color: #0000ff;"><span style="color: #0000ff;">#pragma</span></span>Mark is ready to start dragging-(<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) scrollviewwillbegindragging: (uiscrollview *<span style="color: #000000;"><span style="color: #000000;">) ScrollView {_isdraging</span></span>=<span style="color: #000000;"><span style="color: #000000;">YES; } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">#pragma</span></span>Mark View Stops scrolling-(<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) scrollviewdidenddecelerating: (uiscrollview *<span style="color: #000000;"><span style="color: #000000;">) ScrollView {_isdraging</span></span>=<span style="color: #000000;"><span style="color: #000000;">NO;}</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">#pragma</span></span>Mark has dragged-(<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) Scrollviewdidscroll: (uiscrollview *<span style="color: #000000;"><span style="color: #000000;">) scrollview{</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Static</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>i =<span style="color: #800080;"><span style="color: #800080;">0</span></span>;<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">The first few pictures are currently displayed</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">float</span></span>offset =<span style="color: #000000;"><span style="color: #000000;">scrollview.contentoffset.x; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(_nextimageview.image = = Nil | | _previousview.image = =<span style="color: #000000;"><span style="color: #000000;">Nil) { </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">load the next view</span></span>[_nextimageview Setimagewithurl:[nsurl urlwithstring:[array_pic objectatindex:i = = kCount?<span style="color: #800080;"><span style="color: #800080;">0</span></span>: i+<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">]]]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Load Previous View</span></span>[_previousview Setimagewithurl:[nsurl urlwithstring:[array_pic objectatindex:i = =<span style="color: #800080;"><span style="color: #800080;">0</span></span>? kcount:i-<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">]]]; } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(offset = =<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">) {_currentimageview.image</span></span>=<span style="color: #000000;"><span style="color: #000000;">_previousview.image; Scrollview.contentoffset</span></span>= Cgpointmake (scrollView.bounds.size.width,<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">); _previousview.image</span></span>=<span style="color: #000000;"><span style="color: #000000;">nil; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(i = =<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">) {i</span></span>=<span style="color: #000000;"><span style="color: #000000;">kcount; }</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{i</span></span>-=<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">; } } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(offset = = ScrollView.bounds.size.width *<span style="color: #800080;"><span style="color: #800080;">2</span></span><span style="color: #000000;"><span style="color: #000000;">) {_currentimageview.image</span></span>=<span style="color: #000000;"><span style="color: #000000;">_nextimageview.image; Scrollview.contentoffset</span></span>= Cgpointmake (scrollView.bounds.size.width,<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">); _nextimageview.image</span></span>=<span style="color: #000000;"><span style="color: #000000;">nil; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(i = =<span style="color: #000000;"><span style="color: #000000;">Kcount) {i</span></span>=<span style="color: #800080;"><span style="color: #800080;">0</span></span>;<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">resets <span style="color: #008000;">to 0 if the current picture index is the last, otherwise +1</span></span>}<span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{i</span></span>+=<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">; }} [mypagecontrol setcurrentpage:i];}</span></span></pre><p><p></p></p><p><p>IOS about Auto-carousel Pictures</p></p></span>

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.