Search code examples
iphoneobjective-cios5ios4ios6

Touch event methods are not calling in UIPopOverViewController in ipad?


Hi Iam working with UIPopOverViewController in ipad app. I called touches event methods, off course those are automatically called when touch. But those are UIView methods. My problem is I have popOverViewController, in that image-view. when i touch in that image-view, delegate methods are not called.

I do it in another way, it is i sub-view the image view in UIView, in this case delegates are called. when i assigned that image-view to PopOverView, delegates are not called.

here is the sample code :

 if(popOverViewBool) {

 signatureImageView.image=nil;
 [currentTextField resignFirstResponder];
 [currentTextView resignFirstResponder];
 red = 0.0/255.0;
 green = 0.0/255.0;
 blue = 0.0/255.0;
 brush = 2.2;//10.0
 opacity = 1.0;


 UIViewController* popOverVCont = [[UIViewController alloc] init];
 popOverVCont.view=myView;
 popOverVCont.contentSizeForViewInPopover =CGSizeMake(590, 350);

 self.popoverController = [[UIPopoverController alloc]
 initWithContentViewController:popOverVCont];

 popoverController.delegate = self;

 [popoverController presentPopoverFromRect:CGRectMake(-137, 460, 320, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
 popOverViewBool=NO;
 }
 else
 {
 [popoverController presentPopoverFromRect:CGRectMake(-137, 460, 320, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
 }



- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

mouseSwiped = NO;
UITouch *touch = [touches anyObject];
//lastPoint = [touch locationInView:self.view];
lastPoint = [touch locationInView:self.drawSignView];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

mouseSwiped = YES;
UITouch *touch = [touches anyObject];
//CGPoint currentPoint = [touch locationInView:self.view];
CGPoint currentPoint = [touch locationInView:self.drawSignView];

//UIGraphicsBeginImageContext(self.view.frame.size);
UIGraphicsBeginImageContext(self.drawSignView.frame.size);


//[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.drawSignView.frame.size.width, self.drawSignView.frame.size.height)];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush );
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);

CGContextStrokePath(UIGraphicsGetCurrentContext());
self.tempDrawImage.image = UIGraphicsGetImageFromCurrentImageContext();
[self.tempDrawImage setAlpha:opacity];
UIGraphicsEndImageContext();

lastPoint = currentPoint;
 }

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

if(!mouseSwiped)
{
    //UIGraphicsBeginImageContext(self.view.frame.size);
    UIGraphicsBeginImageContext(self.drawSignView.frame.size);


    //[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.drawSignView.frame.size.width, self.drawSignView.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, opacity);
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    CGContextFlush(UIGraphicsGetCurrentContext());
    self.tempDrawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

UIGraphicsBeginImageContext(self.mainImage.frame.size);
//[self.mainImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0];
[self.mainImage.image drawInRect:CGRectMake(0, 0, self.drawSignView.frame.size.width, self.drawSignView.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0];


//[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:opacity];
[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.drawSignView.frame.size.width, self.drawSignView.frame.size.height) blendMode:kCGBlendModeNormal alpha:opacity];
self.mainImage.image = UIGraphicsGetImageFromCurrentImageContext();
self.tempDrawImage.image = nil;
UIGraphicsEndImageContext();
}

i Google it, but i did not find any answer.. Please give any ideas or suggestions.

Thanks


Solution

  • If you want to use touches* series in your view, you gotta make custom class that implements that methods.

    1. In your case, you have to make SomeImageView class which is subclass of UIImageView.

    2. Or you can use subclasses of UIGestureRecognizer like UITapGestureRecognizer or UIPinchGestureRecognizer. in your viewDidLoad of controller,

      self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
      self.tapGestureRecognizer.cancelsTouchesInView = NO;
      self.tapGestureRecognizer.delegate = self;
      self.tapGestureRecognizer.numberOfTapsRequired = 1; // invoked at 1 tap. 
      self.photoScaleFrameView addGestureRecognizer:self.tapGestureRecognizer];
      

    and in your controller.m

        - (void)handleTap:(UITapGestureRecognizer*)recognizer {
               NSLog(@"tap gesture detected");
        }
    

    and bam.