嗨,我是iPhone開發新手。請任何機構告訴我,如果我有兩個意見一個另一個,我想,當我點擊超級查看它會拖動,當我點擊子視圖時,它會拖動。有誰能夠幫助我?如何將觸摸移動控件從一個uiview移動到另一個移動iPhone上的方法
這裏是我的代碼:
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *aTouch = [touches anyObject];
//UITouch *aTouchSuper = [touches anyObject];
CGPoint location = [aTouch locationInView:self.view];
//CGPoint locationSuper=[aTouchSuper locationInView:viewForTouch];
[UIView beginAnimations:@"Dragging A DraggableView" context:nil];
////////////////////////
//if(location.x>50 &&location.x<300){
// viewForTouch.frame = CGRectMake(location.x,0,
// viewForTouch.frame.size.width, viewForTouch.frame.size.height);
//
//
//
// }
UIView *subview = [self.view hitTest:[[touches anyObject] locationInView:self.view] withEvent:nil];
NSLog(@"%i",subview.tag);
if (location.x <= 50)
{
location.x = 50;
}
if (location.x >= 300)
{
location.x = 300;
}
if(subview.tag==12){
viewForTouchInner.frame = CGRectMake(location.x,0,
viewForTouchInner.frame.size.width, viewForTouchInner.frame.size.height);
}
if(subview.tag==11)
{
viewForTouch.frame = CGRectMake(location.x,0,
viewForTouch.frame.size.width, viewForTouch.frame.size.height);
}
///////////////////////
//if(viewForTouchInner.hidden=FALSE){
//
//
//
//
// location.x=0;
// NSLog(@"%f",location.x);
// viewForTouchInner.frame = CGRectMake(location.x,0,
//
// viewForTouch.frame.size.width, viewForTouch.frame.size.height);
//
//
// }
[UIView commitAnimations];
[buttonForMove addTarget:self action:@selector(Show) forControlEvents:UIControlEventTouchUpInside];
}
但你爲什麼使用 - (void)touchesMoved:(NSSet *)觸及事件:(UIEvent *)事件{}。此方法用於從圖像中獲取觸摸事件。從自定義類選項卡更改您的視圖爲UIcontroll比它會得到觸摸事件。 – freelancer 2012-04-18 06:41:16