objective-c – 在UIPopoverController中丢失手势识别器

我有一个名为PhotoBoothController的类,我用它来使用手势操作图像.我在iPhone上运行时工作正常.但是当我在iPad上运行它时,我在UIPopoverController中显示PhotoBoothController.图像显得很好,但我无法操纵它,因为我的手势似乎无法被识别.我不知道如何让UIPopoverController控制手势.

我提出了popovercontroller并配置了视图:

- (void)presentPhotoBoothForPhoto:(UIImage *)photo button:(UIButton *)button {

    //Create a photoBooth and set its contents
    PhotoBoothController *photoBoothController = [[PhotoBoothController alloc] init];
    photoBoothController.photoImage.image = [button backgroundImageForState:UIControlStatenormal];

    //set up all the elements programmatically.
    photoBoothController.view.backgroundColor = [UIColor whiteColor];

    //Add frame (static)
    UIImage *frame = [[UIImage imageNamed:@"HumptyLine1Frame.png"] adjustForResolution];
    UIImageView *frameView = [[UIImageView alloc] initWithImage:frame];
    frameView.frame = CGRectMake(50,50,frame.size.width,frame.size.height);
    [photoBoothController.view addSubview:frameView];

    //Configure image
    UIImageView *photoView = [[UIImageView alloc] initWithImage:photo];
    photoView.frame = CGRectMake(50,photo.size.width,photo.size.height);
    photoBoothController.photoImage = photoView;

    //Add canvas
    UIView *canvas = [[UIView alloc] initWithFrame:frameView.frame];
    photoBoothController.canvas = canvas;
    [canvas addSubview:photoView];
    [canvas becomeFirstResponder];

    [photoBoothController.view addSubview:canvas];
    [photoBoothController.view bringSubviewToFront:frameView];

    //resize the popover view shown in the current view to the view's size
    photoBoothController.contentSizeforViewInPopover = CGSizeMake(frameView.frame.size.width+100,frameView.frame.size.height+400);

    self.photoBooth = [[UIPopoverController alloc] initWithContentViewController:photoBoothController];
    [self.photoBooth presentPopoverFromrect:button.frame
                                     inView:self.view
                   permittedArrowDirections:UIPopoverArrowDirectionAny
                                   animated:YES];
}

我认为[canvas becomeFirstResponder]可能会这样做,但它似乎没有什么区别.

任何建议都非常感谢,谢谢.

更新:根据评论添加代码

- (void)viewDidLoad {
  [super viewDidLoad];

  if (!_marque) {
    _marque = [CAShapeLayer layer];
    _marque.fillColor = [[UIColor clearColor] CGColor];
    _marque.strokeColor = [[UIColor grayColor] CGColor];
    _marque.linewidth = 1.0f;
    _marque.lineJoin = kCALineJoinRound;
    _marque.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:5],nil];
    _marque.bounds = CGRectMake(photoImage.frame.origin.x,photoImage.frame.origin.y,0);
    _marque.position = CGPointMake(photoImage.frame.origin.x + canvas.frame.origin.x,photoImage.frame.origin.y + canvas.frame.origin.y);
  }
  [[self.view layer] addSublayer:_marque];

  UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
  [pinchRecognizer setDelegate:self];
  [self.view addGestureRecognizer:pinchRecognizer];

  UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
  [rotationRecognizer setDelegate:self];
  [self.view addGestureRecognizer:rotationRecognizer];

  UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
  [panRecognizer setMinimumNumberOftouches:1];
  [panRecognizer setMaximumNumberOftouches:1];
  [panRecognizer setDelegate:self];
  [canvas addGestureRecognizer:panRecognizer];

  UITapGestureRecognizer *tapProfileImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
  [tapProfileImageRecognizer setNumberOfTapsrequired:1];
  [tapProfileImageRecognizer setDelegate:self];
  [canvas addGestureRecognizer:tapProfileImageRecognizer];

}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  return ![gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && ![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]];
}

解决方法

我正在研究类似的应用程序,我可以轻松地在画布上操作图像.

1)检查画布的userInteractionEnabled属性是否设置为YES.2)您可以尝试将手势添加到ImageView而不是画布. (我猜你想要缩放,旋转n滑动图像).

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...