Charles D'Monte
Charles D'Monte

Reputation: 372

Move superview when moving subview - ObjectiveC

I have a superUIView which has a subUIView. The subUIView has the UIPanGestureRecognizer.

I need to move the superUIView when the user tries to move the subUIView.

I do not want to set the center as that would give a jerk.

I need to move the superUIView smoothly when the user tries to move the subUIView.Because the superUIView is moving, the user will get the feeling that he is moving the subUIView.

So, I how do I get this done?

Upvotes: 0

Views: 571

Answers (2)

Fonix
Fonix

Reputation: 11597

assuming you set the frame of the subUIView when the gesture recognizer triggers, just move the super view the same amount

subview.frame = CGRectMake(-x,-y,w,h); //move opposite way to superview
[subview superview].frame = CGRectMake(x,y,w,h); //move

edit: misinterpreted what you were trying to accomplish a bit, you would need to move the subview the opposite way to which the superview is moving for the subview to stay in place while the superview moves

Upvotes: 0

amar
amar

Reputation: 4343

You can set the center to avoid jerk use UIView animation block

[UIView animateWithDuration:0.5
                         animations:^{
                            //set center here
                         }
                         completion:^(BOOL finished) {

                         }];

Upvotes: 1

Related Questions