2017-02-23 77 views
-1

enter image description here如何在水平滚动时使中心图像变大?

当我水平滚动收集视图时,中心图像应该比其他图像大。如何实现这一目标?

+1

使用[iCarousel](https://github.com/nicklockwood/iCarousel) – pkc456

+0

您可以获取中心图像并对其应用比例转换。 –

+0

如何从集合视图中获取中心图像? – Mathi

回答

-2

你可以尝试iCarousel并改变主图像大小。

0

您可以使用icarousel视图。

@property (strong, nonatomic) IBOutlet iCarousel *viewICarousel; 

使用这种方法:

- (void)viewDidLoad 
{ 
    _viewICarousel.dataSource = self; 
    _viewICarousel.delegate = self; 
    _viewICarousel.pagingEnabled = YES; 
    _viewICarousel.type = iCarouselTypeLinear; //user different type 

    [_viewICarousel reloadData]; 

    } 
    - (CGFloat)carouselItemWidth:(iCarousel *)carousel 
    { 
     return (self.view.frame.size.width * 248/320); //Method use for width set of view 
    } 
    - (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value 
    { 
     if (option == iCarouselOptionSpacing) 
     { 
      return value * 1.164; // Space between view 
     } 
     return value; 
    } 

    - (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel 
    { 
     return _arrCampaignData.count; 
    } 
    - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(nullable UIView *)view 
    { 
     UILabel *label = nil; 
     UIImageView *imgView = nil; 

     if (view == nil) 
     { 
      view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, (self.view.frame.size.width * 278.0/320), _viewICarousel.frame.size.height)]; 
      view.contentMode = UIViewContentModeCenter; 
      view.backgroundColor = [UIColor clearColor]; 

      CGRect rectImage = view.bounds; 
      imgView = [[UIImageView alloc]initWithFrame:rectImage]; 
      [view addSubview:imgView]; 
     } 
     else 
     { 
      label = (UILabel *)[view viewWithTag:1]; 
     } 

     imgView.backgroundColor = [UIColor colorWithRed:41/255.0 green:171/255.0 blue:135/255.0 alpha:0.3]; 
     label.text = [NSString stringWithFormat:@"%@",_arrCampaignData[index][KEY_COMPAIGN_NAME]]; 
     NSString *strURL = [NSString stringWithFormat:@"%@",_arrCampaignData[index][KEY_CAMPAIGN_BANNER]]; 
     [imgView sd_setImageWithURL:[NSURL URLWithString:strURL]]; 

     return view; 
    } 
    - (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index 
    { 
     //select view 
    } 

希望这是给你的帮助。