将图像视图作为子视图从一个图像视图更改为另一个图像视图
我正在创建一个应用程序,其中我有两个小图像视图(每个都使用屏幕) 其中一个视图有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否完全理解您问题的细节;无论如何,如果我正确地解释了这句话:
我认为你应该设置
UIImageView的
您进行移动,使其出现在目标超级视图中的正确位置。frame
属性除此之外,删除然后添加为子视图对我来说似乎是正确的方法。如果此回复没有帮助,您可以尝试发布一些代码,可能还发布一些快照,以使您的观点更加明显。
I am not sure I fully understand the details of your question; anyway if I correctly interpret the sentence:
I think you should set the
frame
property of theUIImageView
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.