简体   繁体   English

移动子视图时移动超级视图-ObjectiveC

[英]Move superview when moving subview - ObjectiveC

I have a super UIView which has a sub UIView . 我有一个超级UIView ,其中有一个子UIView The sub UIView has the UIPanGestureRecognizer . UIView具有UIPanGestureRecognizer

I need to move the super UIView when the user tries to move the subUIView . 当用户尝试移动subUIView时,我需要移动超级UIView

I do not want to set the center as that would give a jerk. 我不想设置中心,因为那样会令人讨厌。

I need to move the super UIView smoothly when the user tries to move the sub UIView .Because the super UIView is moving, the user will get the feeling that he is moving the sub UIView . 当用户尝试移动子UIView时,我需要平稳地移动超级UIView 。由于超级UIView在移动,因此用户会感觉到他在移动子UIView

So, I how do I get this done? 那么,我该如何完成呢?

You can set the center to avoid jerk use UIView animation block 您可以设置中心以避免猛拉使用UIView动画块

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

                         }];

assuming you set the frame of the subUIView when the gesture recognizer triggers, just move the super view the same amount 假设您在手势识别器触发时设置了subUIView的框架,只需将超级视图移动相同的数量

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 编辑:误解了您要完成的工作,您将需要以与父视图相反的方式移动子视图,以使子视图在父视图移动时保持原位

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM