我有一個UIViewController
其中包含2 UIScrollViews
,scrollView1
,scrollView2
例如。移動UIView到另一個UIView
scrollView1
包含許多UIViews
,敲擊的時候它的一個UIViews
我希望它移動到scrollView2
當輕敲UIView
屬於scrollView1
的UIViewController
內的方法被調用,view
爲傳遞參數。
我有一個UIViewController
其中包含2 UIScrollViews
,scrollView1
,scrollView2
例如。移動UIView到另一個UIView
scrollView1
包含許多UIViews
,敲擊的時候它的一個UIViews
我希望它移動到scrollView2
當輕敲UIView
屬於scrollView1
的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 = destinationPointInSecondScrollView;
}];
假如你有這兩個scrollViews聲明爲屬性:
- (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使用動畫,我怎麼能結合這在動畫? – jkigel