gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:32:32 25 4
gpt4 key购买 nike

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

我呈现 popovercontroller 并配置 View :

- (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, 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, 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]];
}

最佳答案

我正在开发一个类似的应用程序,我可以轻松地在 Canvas 上操作图像。

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

关于objective-c - 在 UIPopoverController 中丢失手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10452075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com