CGAffineTransformRotate 之后对 UIImage 进行 TouchMoved 拖动导致图像旋转离开屏幕
我不知道为什么在 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];
}
I'm not sure why after calling this CGAffineTransform method on a UIImageView and then trying to drag it, causes it to spin out of view. Any help is appreciated.
- (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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
transform
属性不是标识,则frame
属性未定义。您不应该从中读取或写入。相反,您应该使用center
和bounds
属性。同样在您的
-setRotation
中,前两行是无用的。第一行分配一个值,然后被第二行覆盖。第二行的最终效果是将身份分配回变量(0, 0 的翻译是什么)。该方法可以只是If the
transform
property is anything other than the identity, theframe
property is undefined. You should not read from it or write to it. Instead you should use thecenter
andbounds
properties.Also in your
-setRotation
, the first 2 lines are useless. The first line assigns a value, which is then overwritten by the second line. The second line's net effect is to assign the identity back to the variable (a translation of 0, 0 is nothing). The method could instead just be