2012-04-18 11 views
1

こんにちは、私はiPhone devの新機能です。私は2つのビューを1つずつ持っていれば誰にでも教えてくれますし、スーパービューをクリックするとドラッグして、サブビューをクリックするとドラッグします。誰か助けてくれますか?iPhoneでtouchesMovedメソッドを使用すると、1つのuiviewから別のuiviewにコントロールを移動する方法

-(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]; 
} 
+0

が、なぜあなたが使用している - (ボイド)touchesMoved:(NSSet *)withEventに触れる:(たUIEvent *)イベント{}。このメソッドは画像からタッチイベントを取得するために使用されます。カスタムクラスのタブからUIcontrollにビューを変更すると、タッチイベントが表示されます。 – freelancer

答えて

0

ここIOSのスーパーでビューをドラッグするために私のコードは次のとおりです。

は、ここに私のコードです。 はまた、フレームワークQuartzCore/QuartzCoreを追加する必要があります。このボタンは、このアクションは注意をサブビューをx == 0に配置されている場合、それは、X = 260にそれをアニメーションチェックし、その逆も012​​called.Itタップ私はsubview.when上のボタンを持っていると仮定し、 をドラッグのごaction.setAnimationDurationショーの期間の.Mファイル内の#import QuartzCore/QuartzCore.hは - (IBAction)listButtonTapped {

ここ
// [self.navigationController popViewControllerAnimated:YES]; 
    //[self.profileTableView reloadData]; 
    NSLog(@"ButtonTapped"); 
    if(profileView.frame.origin.x == 0){ 
     [UIView beginAnimations:@"advancedAnimations" context:nil]; 
     [UIView setAnimationDuration:3.0]; 
     CGRect aFrame = profileView.frame; 
     aFrame.origin.x = 260; 
     profileView.frame = aFrame; 

     [UIView commitAnimations]; 
    } 
    else{ 

     [UIView beginAnimations:@"advancedAnimations" context:nil]; 
     [UIView setAnimationDuration:3.0]; 
     CGRect aFrame = profileView.frame; 
     aFrame.origin.x = 0; 
     profileView.frame = aFrame; 

     [UIView commitAnimations]; 


    } 



} 

enter image description here
ボタンを押すとビューがx位置 enter image description hereの増加に向けてドラッグしています

he再イメージの終了ドラッグプロセス 今度は、再度白サブビューの左側のボタンを押すと、x = 0の位置に戻ります。 私はそれがあなたを助けてくれることを願っています!

+0

それは私のために働くありがとう –

関連する問題