【问题标题】:CGAffineTransformMakeRotation UIView corruptionCGAffineTransformMakeRotation UIView 损坏
【发布时间】:2013-11-09 14:47:35
【问题描述】:

我在旋转 UIView 时遇到了一个问题。

我有一个名为“updatePositions”的方法,它将视图的当前帧设置为超级视图的左侧或右侧,然后调用旋转函数来旋转整个 UIView。但是,当我调用它时,框架设置得很好,但是旋转完全破坏了视图。

在我的布局子视图中,我创建了一个标签和贝塞尔路径,每个标签仅在标签不存在时才创建,并使用视图的 bounds 属性进行布局。

我是在错误的地方调用 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];
    }
}

【问题讨论】:

    标签: ios iphone objective-c uiview cgaffinetransform


    【解决方案1】:

    您正在使用不喜欢转换的自动布局,或者您不止一次调用updatePosition,因此您正在更改已转换视图的frame,这将导致您很多痛。添加

    self.transform = CGAffineTransformIdentity;
    

    作为updatePosition的第一行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-15
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      相关资源
      最近更新 更多