我使用iCarousel用于loading youtube videos
。当我们滚动iCarousel相应的YouTube网址加载并播放video.For为此我使用的WebView加载urls.I还需要在每个旋转视图一个按钮,这样我可以实现一个动作时,点击相应的旋转视图即使在视频加载时用户轻按在旋转视图应该采取行动应对。
旋转木马的方法:
编辑:
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return 5;
}
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel1
{
UIWebView *WEBPreviuos = (UIWebView *)[[carousel1 itemViewAtIndex:previousIndex] viewWithTag:2];
[WEBPreviuos loadHTMLString:nil baseURL:[[NSBundle mainBundle] resourceURL]];
previousIndex=carousel1.currentItemIndex;
UIWebView *WEB = (UIWebView *)[[carousel1 itemViewAtIndex:carousel1.currentItemIndex] viewWithTag:2];
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>";
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, WEB.frame.size.width, WEB.frame.size.height,@"5H9jnUqTXeQ"];
[WEB loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIWebView *youTubeWebView=nil;
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 180)];
view.userInteractionEnabled=YES;
((UIImageView *)view).image = [UIImage imageNamed:@"page.png"];
view.contentMode = UIViewContentModeCenter;
youTubeWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 280, 180)];
//youTubeWebView.scalesPageToFit = YES;
youTubeWebView.backgroundColor=[UIColor blackColor];
youTubeWebView.opaque=NO;
youTubeWebView.tag=2;
youTubeWebView.userInteractionEnabled=YES;
youTubeWebView.mediaPlaybackRequiresUserAction=NO;
youTubeWebView.delegate = self;
[view addSubview:youTubeWebView];
UIButton *VideoButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
VideoButton.frame=CGRectMake(0, 0, 280, 180);
VideoButton.userInteractionEnabled=YES;
VideoButton.backgroundColor=[UIColor clearColor];
[VideoButton addTarget:self action:@selector(VideoButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[youTubeWebView addSubview:VideoButton];
[view bringSubviewToFront:youTubeWebView];
}
else
{
//get a reference to the label in the recycled view
youTubeWebView=(UIWebView*) [view viewWithTag:2];
}
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>";
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, youTubeWebView.frame.size.width, youTubeWebView.frame.size.height,@"5H9jnUqTXeQ"];
if(index==0)
{
// label.text = [MainIndexArray objectAtIndex:index];
[youTubeWebView loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
}
else
{
[youTubeWebView loadHTMLString:nil baseURL:[[NSBundle mainBundle] resourceURL]];
}
return view;
}
我现在用的传送带此purpose.When我用web视图按钮下面的按钮下面一个按键是不是responding.When我使用了滚动按钮上方,则该按钮的作品,但是当我们拖动转盘的中央视图旋转木马是不是滚动。
所以,请建议我该怎么办?我需要一个相应的旋转视图点击与它的WebView时只是一个动作。