0

我不确定为什么在 UIImageView 上调用此 CGAffineTransform 方法然后尝试拖动它后,会导致它旋转出视图。任何帮助表示赞赏。

- (void)setRotation:(Float32)rotation {
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(0.0,0.0);
transform = CGAffineTransformRotate(transform, degreesToRadians(rotation));
[self setTransform:transform];
}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {

CGPoint pt = [[touches anyObject] locationInView:self];
CGRect frame = [self frame];

frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;

[self setFrame:frame];

}
4

1 回答 1

1

如果该transform属性不是身份,则该frame属性是未定义的。您不应该从中读取或写入。相反,您应该使用centerandbounds属性。

同样在你的-setRotation,前两行是没用的。第一行分配一个值,然后被第二行覆盖。第二行的净效果是将标识分配回变量(0 的翻译,0 什么都不是)。该方法可能只是

self.transform = CGAffineTransformMakeRotation(degreesToRadians(rotation));
于 2011-02-08T01:33:02.413 回答