我不确定为什么在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];
}
答案 0 :(得分:1)
如果transform
属性不是标识,则frame
属性未定义。你不应该从中读取或写入它。相反,您应该使用center
和bounds
属性。
同样在你的-setRotation
中,前两行是无用的。第一行分配一个值,然后由第二行覆盖。第二行的净效果是将身份分配回变量(0的转换为0,什么都不是)。该方法可能只是
self.transform = CGAffineTransformMakeRotation(degreesToRadians(rotation));