2012-10-29 18 views
0

我有一個視圖在iPad中。 在這個觀點上,我有四個按鈕。 現在,當我點擊那個按鈕時,一個視圖打開一些固定的高度,寬度,x位置和y位置。 我想讓這個新視圖可以停靠。 我的意思是我想把這個視圖拖到那個大視圖的任何地方。使視圖浮在一些其他視圖

回答

0

落實following

  1. – touchesBegan:withEvent:

  2. – touchesMoved:withEvent:

  3. – touchesEnded:withEvent:

  4. – touchesCancelled:withEvent:

並使用觸摸的位置來設置uview的框架。這樣做並不複雜。

快速谷歌搜索產生了這個tutorial

0

您可以在您的情況優化這個..

-(void)dragging:(UIPanGestureRecognizer *)gesture 
{ 
if(gesture.state == UIGestureRecognizerStateBegan) 
{ 
//NSLog(@"Received a pan gesture"); 
self.panCoord = [gesture locationInView:gesture.view]; 


} 
CGPoint newCoord = [gesture locationInView:gesture.view]; 
float dX = newCoord.x-panCoord.x; 
float dY = newCoord.y-panCoord.y; 

gesture.view.frame = CGRectMake(gesture.view.frame.origin.x+dX,   gesture.view.frame.origin.y+dY, gesture.view.frame.size.width, gesture.view.frame.size.height); 
} 
+0

什麼panCoord指示? –