touchesMoved在CGAffineTransformRotate后拖动UIImage导致图像旋转屏幕

时间:2011-02-08 01:23:53

标签: iphone uiimageview cgaffinetransform

我不确定为什么在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];

}

1 个答案:

答案 0 :(得分:1)

如果transform属性不是标识,则frame属性未定义。你不应该从中读取或写入它。相反,您应该使用centerbounds属性。

同样在你的-setRotation中,前两行是无用的。第一行分配一个值,然后由第二行覆盖。第二行的净效果是将身份分配回变量(0的转换为0,什么都不是)。该方法可能只是

self.transform = CGAffineTransformMakeRotation(degreesToRadians(rotation));