旋转的UIView和核心图形的界限

时间:2013-04-09 18:50:41

标签: iphone uiview core-graphics cgaffinetransform

我有一个UIView的子类,它正在绘制一个位置图标。当我将视图旋转几度时,它的边界(使用CGContextAddRect以绿色突出显示)似乎发生了巨大变化,导致我的绘图看起来变形。

http://bytolution.com/Screenshot%202013.04.09%2016.41.00.png http://bytolution.com/Screenshot%202013.04.09%2016.41.43.png

这是我的代码:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.locationTagView.frame = CGRectMake(40, 80, 240, 240);
    CGAffineTransform transform = CGAffineTransformMakeRotation(DegreesToRadians(30));
    self.locationTagView.transform = transform;
    [self.view addSubview:self.locationTagView];
}

1 个答案:

答案 0 :(得分:2)

这解决了它:

#define LOCTAG_HEIGHT 240
#define LOCTAG_WIDTH 240

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.locationTagView.frame = CGRectMake(40, 80, LOCTAG_WIDTH, LOCTAG_HEIGHT);
    self.locationTagView.bounds = CGRectMake(0, 0, LOCTAG_WIDTH, LOCTAG_HEIGHT);
    CGAffineTransform transform = CGAffineTransformMakeRotation(DegreesToRadians(340));
    self.locationTagView.transform = transform;
    [self.view addSubview:self.locationTagView];
}

http://bytolution.com/Screenshot%202013.04.09%2021.02.39.png

单独设置边界使其有效!