2013-11-09 44 views
0

我有點堅持用旋轉一個UIView時,我有一個問題。CGAffineTransformMakeRotation UIView的腐敗

我有一個叫做「updatePositions」方法,該方法將視圖的當前幀的左側或在上海華的右側,然後調用旋轉功能來旋轉整個的UIView。但是,當我稱之爲,框架設置良好,但旋轉完全破壞視圖。

在我的佈局子視圖,我創建了一個標籤和貝塞爾路徑,每個如果標籤不存在,才能創建和使用視圖的邊界屬性的佈局。

上午我打電話CGAffineTransformMakeRotation放錯了地方?

- (void)updatePosition 
{ 
    // If the join overview orientates to north set position 
    if (self.joinOverview.doesOrientateToNorth) 
     // If the approach track is not south west place the north indicator in the lower left of the diagram 
     // if approach track is south west place north indicator in lower right 
     if (self.joinOverview.dataItem.approachTrack != VDApproachTrackSouthWest) 
      [self setFrame:CGRectMake(-self.superview.frame.origin.x, self.superview.frame.size.height - VIEW_SIZE, VIEW_SIZE, VIEW_SIZE)]; 
     else 
      [self setFrame:CGRectMake(self.superview.frame.size.width - VIEW_SIZE, self.superview.frame.size.height - VIEW_SIZE, VIEW_SIZE, VIEW_SIZE)]; 
    } 
    else // If the join overview orientates to the approach track set rotation and position 
    { 
     // Set the position to the lower left of the view 
     [self setFrame:CGRectMake(-self.superview.frame.origin.x, self.superview.frame.size.height - VIEW_SIZE, VIEW_SIZE, VIEW_SIZE)]; 

     // Rotate 
     self.transform = CGAffineTransformMakeRotation(DegreesToRadians(50)); 
    } 
} 


- (void)layoutSubviews 
{ 
    // Super 
    [super layoutSubviews]; 

    // set background colour to transparent 
    self.backgroundColor = [UIColor clearColor]; 

    if (!self.northSymbol) { 
    // Add 'N' symbol label 
    self.northSymbol = [[UILabel alloc]initWithFrame:CGRectMake(0, self.bounds.size.height/2, self.bounds.size.width, self.bounds.size.height/2)]; 
    [self.northSymbol setText:@"N"]; 
    [self.northSymbol setTextAlignment:NSTextAlignmentCenter]; 
    [self.northSymbol setFont:[UIFont boldSystemFontOfSize:18]]; 
    [self addSubview:self.northSymbol]; 

    self.arrow = [UIBezierPath bezierPathWithThreePointArrowFromPoint:CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2) 
    toPoint:CGPointMake(self.bounds.size.width/2, self.bounds.size.height/20) 
    headWidth:self.bounds.size.width/2.5]; 
    } 
} 

回答

0

要麼你正在使用自動佈局,不喜歡變換,或者你打電話updatePosition不止一次,因此你改變已經改變觀點的frame,這將導致你很多的疼痛。添加

self.transform = CGAffineTransformIdentity; 

作爲第一行updatePosition