2013-09-05 1 views
2

UIImageView가 왜 회전하지 않습니까?왜 UIImageView가 회전하지 않습니까?

센터 프레임 주위로 세그먼트를 렌더링해야하지만 회전하지는 않습니다.

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     _baseImage = [UIImage imageNamed:@"setAlarmSegment.png"]; 
     _segmentCircleArray = [[NSMutableArray alloc] initWithCapacity:16];  
     for (int i=0; i<16; i++) { 
      UIImageView *imageViewSegment = [[UIImageView alloc] initWithImage:_baseImage]; 
      [imageViewSegment setFrame:self.frame]; 
      imageViewSegment.transform = CGAffineTransformMakeRotation((M_PI*2/16.0f)*i); 
      [_segmentCircleArray addObject:imageViewSegment]; 
     } 
     self.backgroundColor = [UIColor colorWithWhite:0 alpha:0];  
    } 
    return self; 
} 


- (void)drawRect:(CGRect)rect 
{ 
    for (UIImageView *segment in _segmentCircleArray) { 
     [segment drawRect: rect]; 
    } 
} 

감사합니다.

답변

1

그건 코코아/코코아 터치로 그리는 방법이 아닙니다. 뷰 계층 구조가 아닌 이미지 뷰를 주위에 띄우지 않고 drawRect 메시지를 보냅니다. 이미지 뷰는 뷰 계층 구조의 일부가 아니면 그리기위한 것이 아닙니다.

기본보기의 하위보기로 이미지보기를 추가해야합니다. 그러면 시스템에서 그려줍니다.

일반적으로 가능한 경우 Cocoa/Cocoa Touch에서 drawRect를 사용하지 않으려합니다. 그것은 끝내기가 매우 느린 길입니다.

drawRect를 사용하려면 이미지 뷰가 아닌 이미지 배열을 만들어야합니다. 그런 다음 drawAtPoint 또는 drawInRect를 사용하여 차례로 각각을 그립니다. 그래픽 컨텍스트를 저장 한 다음 각 이미지를 그리기 전에 현재 컨텍스트에 회전을 적용한 다음 그래픽 컨텍스트를 복원해야합니다.

+0

감사합니다. 이제 참조를 읽으려고합니다. – setixela

관련 문제