2014-09-09 2 views
0

J'ai créé un CustomView ganttChartView et l'ai ajouté à partir du storyboard. Maintenant, sur ganttChartView, j'ai une vue UICollection qui représentera timeLine et sera ajoutée par programmation.Autoresignalisation des sous-vues (UICollectionView) sur le changement d'orientation

// Initialize GanttChat View from Interface Builder or Storyboard File 
-(id)initWithCoder:(NSCoder *)aDecoder 
{ 
self= [super initWithCoder:aDecoder]; 
if (self) { 
    self.timeLineHeight =KMinTimeLineCellHeight; 
    self.timeLineCellWidth=kMinTimeLineCellWidth; 
    self.backgroundColor = [UIColor redColor]; 
    self.autoresizesSubviews = YES; 
    } 
return self; 
} 

-(void)reloadTimelineView 
{ 
    [self initializeTimeLineView]; 

    [self.timeLineCollectionView reloadData]; 
} 

-(void) initializeTimeLineView 
{ 
// Initialization of StartDate End Date and DateMode Property 
[self initializeTimeLineDates]; 

// Creating Layout for Collection view 
UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc]init]; 
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 

CGSize cellSize =CGSizeMake(self.timeLineCellWidth, self.timeLineHeight) ; 
flowLayout.itemSize = cellSize ; 
flowLayout.minimumInteritemSpacing= 1.0f; 
flowLayout.minimumLineSpacing=5.0f; 

CGRect timeLineFrame =CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.timeLineHeight); 

// Initialization of CollectionView for TimeLine 
self.timeLineCollectionView = [[UICollectionView alloc] initWithFrame:timeLineFrame collectionViewLayout:flowLayout]; 

    [self.timeLineCollectionView registerClass:[A3TimeLineCollectionViewCell class] forCellWithReuseIdentifier:timeLineCell_ID]; 
self.timeLineCollectionView.backgroundColor = self.timeLineBackgroundColor; 

// Initialization of CollectionView DataSource and Delegate with Start Date and End date and DateMode 
self.timeLineDataSource = [[A3GanttChartTimeLineDelegate alloc] initWithDate:self.startDate andDate:self.endDate withMode:self.dateType]; 

self.timeLineDataSource.gantChartView = self; 
self.timeLineDataSource.timeLineEachCellColor = self.timeLineEachCellColor; 

self.timeLineCollectionView.delegate=self.timeLineDataSource; 
self.timeLineCollectionView.dataSource=self.timeLineDataSource; 


[self addSubview:self.timeLineCollectionView]; 

} 

Maintenant Storyboard J'ai option AutoLayout personnes handicapées et de la taille de l'inspecteur ganttChartView j'ai mis en coin supérieur gauche et fixé de façon à redimensionnée après le changement d'orientation.

enter image description here

Maintenant, le problème est que TimeLineCollection View ne redimensionne sur le changement d'orientation du paysage. Comme son ajouté par programme Donc ce que je dois faire le faire redimensionner sur le changement d'orientation.

Bénéfice mode

enter image description here

mode paysage

enter image description here

Répondre

0

Vous devez également définir coin droit fixe afin de redimensionner après le changement d'orientation

0
self.timeLineCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin; 
+0

Merci pour votre réponse, mais cela n'a pas fonctionné pour moi. Est-il possible que nous utilisions NSLayoutConstraint par programme pour résoudre ce problème. –

0

Je fixé cette émission e utilisant NSLayoutConstraint.

// NSLayoutConstraint for making same width of timelineCollectionView with the GanttChart 

NSLayoutConstraint *timeLineCollectionViewWidth =[NSLayoutConstraint 
            constraintWithItem:self.timeLineCollectionView 
            attribute:NSLayoutAttributeWidth 
            relatedBy:0 
            toItem:self 
            attribute:NSLayoutAttributeWidth 
            multiplier:1.0 
            constant:0]; 

[self addConstraint:timeLineCollectionViewWidth]; 

// NSLayoutConstraint for making same left position of timelineCollectionView with the GanttChart 

NSLayoutConstraint *timeLineCollectionViewLeft = [NSLayoutConstraint 
               constraintWithItem:self.timeLineCollectionView 
               attribute:NSLayoutAttributeLeft 
               relatedBy:NSLayoutRelationEqual 
               toItem:self 
               attribute:NSLayoutAttributeLeft 
               multiplier:1.0f 
               constant:0.f]; 
[self addConstraint:timeLineCollectionViewLeft]; 

// NSLayoutConstraint for seting height of timelineCollectionView 

NSLayoutConstraint *heightConstraint = 
[NSLayoutConstraint constraintWithItem:self.timeLineCollectionView 
          attribute:NSLayoutAttributeHeight 
          relatedBy:NSLayoutRelationEqual 
           toItem:nil 
          attribute:NSLayoutAttributeNotAnAttribute 
          multiplier:1.0 
           constant:self.timeLineHeight]; 
[self.timeLineCollectionView addConstraint:heightConstraint]; 
+0

Marquer cette réponse comme acceptée. – testing

Questions connexes