[英]how to move the control from one uiview to another uiview in iphone?
[英]Move UIView to another UIView
我有一個UIViewController
,它包含2個UIScrollViews
, scrollView1
, scrollView2
。
scrollView1
包含許多UIViews
,拍打它的一個時UIViews
我希望它移動到scrollView2
當點擊屬於scrollView1
的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;
}];
假設您將這兩個scrollView聲明為屬性:
- (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];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.