将UIView移动到另一个UIView

jki*_*gel 4 iphone objective-c uiview ios

我有一个UIViewController其中包含2 UIScrollViews,scrollView1,scrollView2例如.

scrollView1包含很多UIViews,当点击其中一个时,UIViews我希望它进入scrollView2

当点击UIView属于的内容时scrollView1,UIViewController调用内部的方法并将其view作为参数传递.

Lev*_*evi 12

在那种方法中你应该写如下:

[view removeFromSuperview];
[scrollView2 addSubview:view];
Run Code Online (Sandbox Code Playgroud)

编辑:

对于动画移动,您应该尝试以下方法:

CGPoint originalCenter = [self.view convertPoint:view.center fromView:scrollView1];
[view removeFromSuperView];
[self.view addSubview:view];
view.center = originalCenter;

CGPoint destinationPointInSecondScrollView = ; // Set it's value
CGPoint finalCenter = [self.view convertPoint:destinationPointInSecondScrollView fromView:scrollView2];
[UIView animateWithDuration:0.3
                      delay:0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     view.center = finalCenter;
                 } completion:^(BOOL finished) {
                         [view removeFromSuperView];
                         [scrollView2 addSubview:view];
                         view.center = destinationPointInSecondScrollView;
                     }];
Run Code Online (Sandbox Code Playgroud)