【问题标题】:Touch event methods are not calling in UIPopOverViewController in ipad?触摸事件方法没有在 ipad 的 UI PopOver ViewController 中调用?
【发布时间】:2013-04-09 10:18:48
【问题描述】:

您好,我正在 ipad 应用程序中使用 UIPopOverViewController。我调用了触摸事件方法,当然这些是在触摸时自动调用的。但那些是UIView 方法。我的问题是我在那个图像视图中有 popOverViewController。当我触摸该图像视图时,不会调用委托方法。

我用另一种方式来做,我在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();
}

我谷歌它,但我没有找到任何答案.. 请提出任何想法或建议。

谢谢

【问题讨论】:

  • 您是否检查过您的 UIImageview userInterfaceEnable 属性是否为真?
  • 是的,我尝试设置是和否,但没有用

标签: iphone objective-c ios5 ios4 ios6


【解决方案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");
    }

然后砰。

【讨论】:

  • 谢谢@steven kim。我将名为 PoPOverVC 的单独视图控制器和子视图将 PoPOverVC 带到 POpOverViewcontroller。我在 PoPOverVC 本身中编写了 touches 方法。然后他们被叫了。现在它工作正常。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-21
  • 2011-03-29
相关资源
最近更新 更多