2013-04-09 75 views
-1

嗨Iam在ipad應用程序中使用UIPopOverViewController。我稱之爲觸摸事件方法,當然觸摸時會自動調用這些方法。但那些方法是UIView。我的問題是我有popOverViewController,在該圖像視圖。當我觸摸該圖像視圖時,不會調用委託方法。觸摸事件方法不在ipad中的UIPopOverViewController中調用?

我做的另一種方式,這是我的子查看圖像視圖UIView,在這種情況下,代表們呼籲。當我將該圖像視圖分配給PopOverView時,代理不會被調用。

這裏是示例代碼:

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(); 
} 

我谷歌,但我沒有找到任何答案.. 請給任何意見或建議。

感謝

+0

你檢查你的UIImageView userInterfaceEnable財產是真還是假? – Tirth 2013-04-09 10:25:17

+0

是的,我試圖設置是和否,但沒有使用 – 2013-04-09 10:26:02

回答

1

如果你想使用touches*系列在你看來,你得做一個實現該方法自定義類。

  1. 你的情況,你必須做出SomeImageView類是UIImageView子類。

  2. 或者您可以使用UIGestureRecognizer的子類,如UITapGestureRecognizerUIPinchGestureRecognizer。在你的控制器的viewDidLoad

    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]; 
    

,並在您Controller.m或者

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

和巴姆。

+0

謝謝@steven kim。我把獨立的視圖控制器稱爲PoPOverVC和子視圖,PoPOverVC到POpOverViewcontroller。我在PoPOverVC本身寫了觸摸方法。然後他們被叫了。現在它工作正常。非常感謝你。 – 2013-04-10 04:30:41

+0

@Mahesh很高興聽到它的工作:) – 2013-04-10 08:23:56