Iphone 将UIView移动到另一个UIView

Iphone 将UIView移动到另一个UIView,iphone,objective-c,ios,uiview,Iphone,Objective C,Ios,Uiview,我有一个UIViewController,它包含2个uiscrollview,scrollView1,scrollView2 scrollView1包含许多UIView,当点击其中一个UIView时,我希望它移动到scrollView2 点击属于scrollView1的UIView时,调用UIViewController中的一个方法,并将视图作为参数传递。在该方法中,您应该编写如下内容: [view removeFromSuperview]; [scrollView2 addSubview:vi

我有一个
UIViewController
,它包含2个
uiscrollview
scrollView1
scrollView2

scrollView1
包含许多
UIView
,当点击其中一个
UIView
时,我希望它移动到
scrollView2


点击属于
scrollView1
UIView
时,调用
UIViewController
中的一个方法,并将
视图作为参数传递。

在该方法中,您应该编写如下内容:

[view removeFromSuperview];
[scrollView2 addSubview:view];
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;
                     }];
编辑

对于动画移动,您应该尝试以下操作:

[view removeFromSuperview];
[scrollView2 addSubview:view];
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;
                     }];

假设将这两个滚动视图声明为属性:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)]
    for (UIView *view in self.scrollView1.subviews) {
        [view addGestureRecognizer:gesture];
    }
}

- (void)viewTapped:(UITapGestureRecognizer *)gesture
{
    UIView *view = gesture.view;
    [self moveToScrollView2:view];
}

- (void)moveToScrollView2:(UIView *)view
{
    [view removeFromSuperview];
    [self.scrollView2 addSubview:view];
}

谢谢,但是我想让视图实际移动到使用动画的scrollView2中,我如何在动画中结合这个?