将图像视图作为子视图从一个图像视图更改为另一个图像视图

发布于 2024-12-27 00:27:41 字数 795 浏览 3 评论 0原文

我正在创建一个应用程序,其中我有两个小图像视图(每个都使用屏幕) 其中一个视图有一个 uiimageview 作为子视图,我需要将此视图更改为 otherImageView 的子视图,将其拖动到它之后,我正在使用removeFromSuperview:& addSubview: 方法,但问题是位置的引用是第一个 imageView,这就是为什么我在新的超级视图中定位 imageview 时遇到问题... 有更好的方法吗? 我希望这是可以理解的,如果我需要添加一些代码,请告诉我。 非常感谢您

编辑:我正在添加一些我正在使用的代码

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

startPoint_ = [[touches anyObject] locationInView:self];
CGPoint newPoint = [[touches anyObject] locationInView:self.superview];
CGRect frm = [self frame];
newPoint.x -= startPoint_.x;
newPoint.y -= startPoint_.y;

frm.origin = newPoint;
currentPoint_.x = frm.origin.x;
currentPoint_.y = frm.origin.y;

}

在此代码的第二行中,我正在定位视图 en self.superview (原始超级视图)。为了更好地管理位置,最好将此位置更改为 self.superview.superview (包含两个视图)。谢谢你!

I am creating an app, in which I have two small imageview (using have of screen each)
One of this views has a uiimageview as a subview, I need to change this view to be a subview of the otherImageView, after I drag it to it, I'm using removeFromSuperview: & addSubview: methods, but the problem is that the reference of the position is the first imageView, that is why I'm having problems positioning the imageview in the new superview...
Is there a better way to do this?
I hope this is understandable, if I need to put some code, let me know.
Thank you so much

Edit: I'm adding some code that I'm using

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

startPoint_ = [[touches anyObject] locationInView:self];
CGPoint newPoint = [[touches anyObject] locationInView:self.superview];
CGRect frm = [self frame];
newPoint.x -= startPoint_.x;
newPoint.y -= startPoint_.y;

frm.origin = newPoint;
currentPoint_.x = frm.origin.x;
currentPoint_.y = frm.origin.y;

}

In the second line of this code I'm locating the view en self.superview (the origin superview). In order to manage better the position, could be a good idea to change this location to self.superview.superview (that is containing both views). Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

唱一曲作罢 2025-01-03 00:27:41

我不确定我是否完全理解您问题的细节;无论如何,如果我正确地解释了这句话:

问题是位置的参考是第一个 imageView,这就是为什么我在新的超级视图中定位 imageview 时遇到问题

我认为你应该设置UIImageView的frame属性 您进行移动,使其出现在目标超级视图中的正确位置。

除此之外,删除然后添加为子视图对我来说似乎是正确的方法。如果此回复没有帮助,您可以尝试发布一些代码,可能还发布一些快照,以使您的观点更加明显。

I am not sure I fully understand the details of your question; anyway if I correctly interpret the sentence:

the problem is that the reference of the position is the first imageView, that is why i'm having problems positioning the imageview in the new superview

I think you should set the frame property of the UIImageView you move so that it appears in the proper location in the destination superview.

Apart from that, removing and then adding as a subview seems the correct approach to me. If this reply does not help, you could try and post some code and possibly some snapshots to make your point more evident.

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