- (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获得当前可见的视图?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)