Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top