CGAffineTransformRotate 之后对 UIImage 进行 TouchMoved 拖动导致图像旋转离开屏幕

发布于 2024-10-16 02:47:28 字数 634 浏览 7 评论 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];

}

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め七分饶幸 2024-10-23 02:47:28

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

同样在您的 -setRotation 中,前两行是无用的。第一行分配一个值,然后被第二行覆盖。第二行的最终效果是将身份分配回变量(0, 0 的翻译是什么)。该方法可以只是

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

If the transform property is anything other than the identity, the frame property is undefined. You should not read from it or write to it. Instead you should use the center and bounds 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

self.transform = CGAffineTransformMakeRotation(degreesToRadians(rotation));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文