Prerna chavan
Prerna chavan

Reputation: 3249

Reposition UIView keeping its subview position unchanged

How to reposition UIView keeping its subview at same position before reposition. When i move the UIView its subview are also getting moved.How can i avoid that. I just want to move the parent view not its subviews.

Upvotes: 0

Views: 940

Answers (1)

Kevin Low
Kevin Low

Reputation: 2682

Since that's not how view hierarchy works, unless I am mistaken, there's no way to prevent a subview from moving with its superview.

What you could do is reposition the subview while the superview is moving (but don't animate it) so it gives the illusion that it doesn't move.

The way I'd do it within these restrictions is to get the position of the subview in relation to the superview's superview (convertRect:toView: method) then simply set the frame's origin every time your superview is moving.

Upvotes: 1

Related Questions