2014-09-09 5 views
0

사용자 정의 뷰 ganttChartView를 작성하고 스토리 보드에서 추가했습니다. 이제 ganttChartView에서 나는 timeLine을 나타내고 프로그램 적으로 추가 된 UICollection View를 가지고있다. 방향 변경시 하위 뷰 (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]; 

} 

이제 스토리 보드에서 나는 장애인 자동 레이아웃 옵션을 가지고이 방향 변경 후 크기를 조정할 수 있도록 ganttChartView의 크기 경위에서 나는 상단과 왼쪽 모서리에 고정 설정했습니다.

enter image description here

이제 문제는 TimeLineCollection보기 가로로 방향 변경에 크기 조정되지 않는 것입니다. 프로그래밍 방식으로 추가되었으므로 오리엔테이션 변경시 크기를 조정해야합니다.

이익 모드

enter image description here

풍경 모드 또한 방향 변경 후 크기를 조정하기 위해 고정 오른쪽 모서리를 설정해야

enter image description here

답변

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