ios – 如何让iCarousel获得当前可见的视图?

ios – 如何让iCarousel获得当前可见的视图?,第1张

概述我正在使用iCarousal,我必须在我的iCarousal视图中使用三个webview,五个imageview和两个Labels共10个iCarousal视图.我需要做的是根据下面的标记获取标签,webviews和imageview方法并在iCarousel移动时更改其值. - (void)carouselCurrentItemIndexDidChange:(iCarousel *)objcar 我正在使用iCarousal,我必须在我的iCarousal视图中使用三个webvIEw,五个imagevIEw和两个Labels共10个iCarousal视图.我需要做的是根据下面的标记获取标签,webvIEws和imagevIEw方法并在iCarousel移动时更改其值.

- (voID)carouselCurrentItemIndexDIDChange:(iCarousel *)objcarousel

我通过objcarousel.currentItemIndex获取iCarousel的当前索引,但是当我用标记获取视图时,我无法获取当前视图.它给出了第二个下一个视图.

码:

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel{    return MainIndexArray.count;}- (voID)carouselCurrentItemIndexDIDChange:(iCarousel *)carousel1{    if(carousel1.currentItemIndex<3)    {    }    else    {        UIWebVIEw *WEB=(UIWebVIEw *) [carousel1 vIEwWithTag:2];        NSLog(@"WEB====%@",WEB);        [WEB stopLoading];        static Nsstring *youTubeVIDeoHTML = @"<!DOCTYPE HTML><HTML><head><style>body{margin:0px 0px 0px 0px;}</style></head> <body> <div ID=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = \"http://www.youtube.com/player_API\"; var firstScriptTag = document.getElementsByTagname('script')[0]; firstScriptTag.parentNode.insertBefore(tag,firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player',{ wIDth:'%0.0f',height:'%0.0f',vIDeoID:'%@',events: { 'onReady': onPlayerReady,} }); } function onPlayerReady(event) { event.target.playVIDeo(); } </script> </body> </HTML>";        NSLog(@"currentItemIndex=====%d",carousel1.currentItemIndex);        Nsstring *HTML = [Nsstring stringWithFormat:youTubeVIDeoHTML,WEB.frame.size.wIDth,WEB.frame.size.height,[YouTubeUrlArray objectAtIndex:0]];        [WEB loadHTMLString:HTML baseURL:[[NSBundle mainBundle] resourceURL]];    } }- (UIVIEw *)carousel:(iCarousel *)carousel vIEwForItemAtIndex:(NSUInteger)index reusingVIEw:(UIVIEw *)vIEw{    UILabel *label = nil;    UIWebVIEw *web=nil;    //create new vIEw if no vIEw is available for recycling    if (vIEw == nil)    {        vIEw = [[UIImageVIEw alloc] initWithFrame:CGRectMake(0,280,200.0f)];        ((UIImageVIEw *)vIEw).image = [UIImage imagenamed:@"page.png"];        vIEw.contentMode = UIVIEwContentModeCenter;        if(index<3)        {            label = [[UILabel alloc] initWithFrame:vIEw.bounds];            label.backgroundcolor = [UIcolor graycolor];            label.textAlignment = NSTextAlignmentCenter;            label.Font = [label.Font FontWithSize:50];            label.tag = 1;            [vIEw addSubvIEw:label];        }        else        {            web=[[UIWebVIEw alloc]initWithFrame:vIEw.bounds];            web.tag=2;            [vIEw addSubvIEw:web];        }    }    else    {        //get a reference to the label in the recycled vIEw        if(index<3)        {            label = (UILabel *)[vIEw vIEwWithTag:1];        }        else        {            web=(UIWebVIEw*) [vIEw vIEwWithTag:2];        }    }    if(index<3)    {        label.text = [MainIndexArray objectAtIndex:index];    }    else    {        [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.Google.com"]]];    }    return vIEw;}

所以请建议我在iCarousel滚动时如何获取当前标签或当前webvIEw或当前imagevIEw.

解决方法 您应该使用itemVIEwAtIndex:with currentItemIndex来获取单个项目视图.然后,在该视图上使用vIEwWithTag :.

问题是vIEwWithTag:搜索所有子视图并返回第一个匹配.如果您在旋转木马本身上运行它,那么您无法保证首先找到哪个视图并返回.

UIWebVIEw *WEB = (UIWebVIEw *)[[carousel1 itemVIEwAtIndex:carousel1.currentItemIndex] vIEwWithTag:2];
总结

以上是内存溢出为你收集整理的ios – 如何让iCarousel获得当前可见的视图?全部内容,希望文章能够帮你解决ios – 如何让iCarousel获得当前可见的视图?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1065916.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存