1.创建
_carousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, 0, 375, 250)]; _carousel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _carousel.type = iCarouselTypeRotary; _carousel.delegate = self; _carousel.dataSource = self; _carousel.tag = 200; [_headView addSubview:_carousel];
2.代理方法
#pragma mark --iCarousel methods - (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel { return [_topData count]; } - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view { if (view == nil) { view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,150, 250)]; view.contentMode = UIViewContentModeCenter; } TopScrollModel *model = _topData[index]; [((UIImageView *)view) sd_setImageWithURL:[NSURL URLWithString:model.poster_url] placeholderImage:[UIImage imageNamed:@"placeImg"]]; return view; } #pragma mark --ICarouselScrollView--- -(void)carouselDidEndScrollingAnimation:(iCarousel * __nonnull)carousel { if (carousel.currentItemIndex == -1) { return; } [self showTopLabelData:carousel.currentItemIndex]; //NSLog(@"%li",carousel.currentItemIndex); } -(void)carousel:(iCarousel * __nonnull)carousel didSelectItemAtIndex:(NSInteger)index { MovieDetailController *mvc = [[MovieDetailController alloc] init]; mvc.movieId = [_topData[index] valueForKey:@"movieId"]; mvc.type = MovieDidPaly; mvc.titleStr = [_topData[index] valueForKey:@"name"]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:mvc animated:YES]; self.hidesBottomBarWhenPushed = NO; }
时间: 2024-10-12 08:56:20