English 中文(简体)
• 如何将控制从一个直观转移到另一个角度 Moved手法
原标题:How to shift control from one uiview to another in touchesMoved method on iPhone

然而,我是在Peterdev。 如果我对另一个机构有两点看法,那么请告诉我,如果我点击超级看法,那就会拖拉,当我点击分观点时,就会拖拉。 谁能帮助我?

我的守则是:

-(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];
}
最佳回答

here is my code to drag view on superview in ios. Suppose i have a button on subview.when this button tapped this action called.It check if subview is placed at x==0 it animated it to x=260,and vice versa Note also you must add framework QuartzCore/QuartzCore and #import QuartzCore/QuartzCore.h in .m file of your action.setAnimationDuration show duration of dragging -(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
here button press and view is dragging towards increasing x position enter image description here

here image end dragging process Now if you again press button above white subview left side it will again come on x=0 position. I hope it will help you!

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签