2017-02-23 76 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 
    } 

希望這是給你的幫助。