4

例如,我有一个UIViewController包含 2UIScrollViews的 , 。scrollView1scrollView2

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

当点击UIView属于 的a 时,将调用scrollView1内部的方法并将作为参数传递。UIViewControllerview

4

2 回答 2

13

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

[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;
                     }];
于 2012-12-19T13:56:07.293 回答
1

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

- (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];
}
于 2012-12-19T14:00:54.053 回答