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

前端之家收集整理的这篇文章主要介绍了objective-c – 在UIPopoverController中丢失手势识别器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个名为PhotoBoothController的类,我用它来使用手势操作图像.我在iPhone上运行时工作正常.但是当我在iPad上运行它时,我在UIPopoverController中显示PhotoBoothController.图像显得很好,但我无法操纵它,因为我的手势似乎无法被识别.我不知道如何让UIPopoverController控制手势.

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

  1. - (void)presentPhotoBoothForPhoto:(UIImage *)photo button:(UIButton *)button {
  2.  
  3. //Create a photoBooth and set its contents
  4. PhotoBoothController *photoBoothController = [[PhotoBoothController alloc] init];
  5. photoBoothController.photoImage.image = [button backgroundImageForState:UIControlStateNormal];
  6.  
  7. //set up all the elements programmatically.
  8. photoBoothController.view.backgroundColor = [UIColor whiteColor];
  9.  
  10. //Add frame (static)
  11. UIImage *frame = [[UIImage imageNamed:@"HumptyLine1Frame.png"] adjustForResolution];
  12. UIImageView *frameView = [[UIImageView alloc] initWithImage:frame];
  13. frameView.frame = CGRectMake(50,50,frame.size.width,frame.size.height);
  14. [photoBoothController.view addSubview:frameView];
  15.  
  16. //Configure image
  17. UIImageView *photoView = [[UIImageView alloc] initWithImage:photo];
  18. photoView.frame = CGRectMake(50,photo.size.width,photo.size.height);
  19. photoBoothController.photoImage = photoView;
  20.  
  21. //Add canvas
  22. UIView *canvas = [[UIView alloc] initWithFrame:frameView.frame];
  23. photoBoothController.canvas = canvas;
  24. [canvas addSubview:photoView];
  25. [canvas becomeFirstResponder];
  26.  
  27. [photoBoothController.view addSubview:canvas];
  28. [photoBoothController.view bringSubviewToFront:frameView];
  29.  
  30. //resize the popover view shown in the current view to the view's size
  31. photoBoothController.contentSizeForViewInPopover = CGSizeMake(frameView.frame.size.width+100,frameView.frame.size.height+400);
  32.  
  33. self.photoBooth = [[UIPopoverController alloc] initWithContentViewController:photoBoothController];
  34. [self.photoBooth presentPopoverFromRect:button.frame
  35. inView:self.view
  36. permittedArrowDirections:UIPopoverArrowDirectionAny
  37. animated:YES];
  38. }

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

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

更新:根据评论添加代码

  1. - (void)viewDidLoad {
  2. [super viewDidLoad];
  3.  
  4. if (!_marque) {
  5. _marque = [CAShapeLayer layer];
  6. _marque.fillColor = [[UIColor clearColor] CGColor];
  7. _marque.strokeColor = [[UIColor grayColor] CGColor];
  8. _marque.lineWidth = 1.0f;
  9. _marque.lineJoin = kCALineJoinRound;
  10. _marque.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:5],nil];
  11. _marque.bounds = CGRectMake(photoImage.frame.origin.x,photoImage.frame.origin.y,0);
  12. _marque.position = CGPointMake(photoImage.frame.origin.x + canvas.frame.origin.x,photoImage.frame.origin.y + canvas.frame.origin.y);
  13. }
  14. [[self.view layer] addSublayer:_marque];
  15.  
  16. UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
  17. [pinchRecognizer setDelegate:self];
  18. [self.view addGestureRecognizer:pinchRecognizer];
  19.  
  20. UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
  21. [rotationRecognizer setDelegate:self];
  22. [self.view addGestureRecognizer:rotationRecognizer];
  23.  
  24. UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
  25. [panRecognizer setMinimumNumberOfTouches:1];
  26. [panRecognizer setMaximumNumberOfTouches:1];
  27. [panRecognizer setDelegate:self];
  28. [canvas addGestureRecognizer:panRecognizer];
  29.  
  30. UITapGestureRecognizer *tapProfileImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
  31. [tapProfileImageRecognizer setNumberOfTapsrequired:1];
  32. [tapProfileImageRecognizer setDelegate:self];
  33. [canvas addGestureRecognizer:tapProfileImageRecognizer];
  34.  
  35. }
  36.  
  37. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  38. return ![gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && ![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]];
  39. }

解决方法

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

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

猜你在找的C&C++相关文章