2014-09-09 3 views
0

Я создал CustomView ganttChartView и добавил его из раскадровки. Теперь на ganttChartView у меня есть UICollection View, который будет представлять timeLine и добавлен программно.Авторезизация подсмотров (UICollectionView) при изменении ориентации

// 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]; 

} 

Теперь из раскадровки я отключил опция AutoLayout и от размера инспектора ganttChartView я установил верхний и левый угол фиксируется так, что она изменяется после изменения ориентации.

enter image description here

Теперь проблема заключается в том, что TimeLineCollection Просмотр не изменение размера на изменения ориентации на альбомную. Поскольку он добавлен программно, то, что мне нужно сделать, изменит ориентацию на изменение ориентации.

Режим Profit

enter image description here

Ландшафтный режим

enter image description here

ответ

0

Вам нужно установить также правый угол неподвижную, чтобы изменить размер после изменения ориентации

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

Спасибо за ваш ответ, но это не сработало для меня. Есть ли способ, которым мы используем NSLayoutConstraint программно для решения этой проблемы. –

0

У меня есть исправлена ​​эта эмиссия используя 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

Отметьте этот ответ как принято. – testing

Смежные вопросы