Question

I Created a sample application, when we click on a button another view(ResizingViewController) view shows up. when i drag ResizingViewController it is moving correctly but i can see another view behind it.I think it is super view (as show in in this image, but not able to make both move at same time).

tinypic.com/r/2qs191g/5

please help me to fix it?(if i drag view then both should move to same position)

my code is as below

- (IBAction)click_Action:(id)sender {

      if (!resizingViewController) {
          return;
      }

      //Creating Right Button, asigning a method to it.
      UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Close"   
            style:UIBarButtonItemStylePlain target:self action:@selector(done)];
            [resizingViewController.navigationItem setRightBarButtonItem:rightButton];

      theNavigationController = [[UINavigationController alloc]    
            initWithRootViewController:resizingViewController];
      [theNavigationController.navigationBar setTintColor:[UIColor blueColor]];
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            theNavigationController.modalPresentationStyle  
                                      =UIModalPresentationFormSheet;
      }
      [self presentViewController:theNavigationController animated:YES completion:nil];

      CGRect r = CGRectMake(100, 100, 300, 400);
      r = [self.view convertRect:r toView:self.view];
      theNavigationController.view.superview.frame = r;

      //Adding gesture reconizer to resizingviewcontroller
      UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] 
                initWithTarget:self action:@selector(handlePanFrom:)];
      [theNavigationController.view addGestureRecognizer:panGestureRecognizer];
}

-(void)handlePanFrom:(UIPanGestureRecognizer *) recognizer
{    
       CGPoint translation = [recognizer translationInView:recognizer.view];

       //Changing Center of the the view as soon as user selects the view and drags
       recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
                                            recognizer.view.center.y +  translation.y);
       CGPoint r = CGPointMake(recognizer.view.center.x+100, 
                                            recognizer.view.center.y+100);
       r = [self.view convertPoint:r toView:self.view];
       recognizer.view.superview.center = r;
       //Should not forget to give below code, else view goes out of bounds.
       [recognizer setTranslation:CGPointZero inView:self.view];

 }
Was it helpful?

Solution

OK i fixed this.(marking this as answer so that if any one have same problem can use this)

-(void)handlePanFrom:(UIPanGestureRecognizer *) recognizer

{

      CGPoint translation = [recognizer translationInView:recognizer.view.superview];
      recognizer.view.superview.center =   
                  CGPointMake(recognizer.view.superview.center.x+translation.x, 
                  recognizer.view.superview.center.y+translation.y);
      [recognizer setTranslation:CGPointZero inView:self.view];

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top