我有一個UIViewController
中包含了兩個UIScrollView
。scrollView1
, scrollView2
。
scrollView1
包含了很多UIViews
,當用到其中一個UIView時我希望能移動到scrollView2
中。
同時在用到UIView的時候,UIViewController會調用其中一個方法,view作為參數傳遞
[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 = convertPoint:destinationPointInSecondScrollView;
}];