gpt4 book ai didi

ios - 嵌入式 ViewContainer 中的手势识别器不会被击中

转载 作者:行者123 更新时间:2023-11-28 21:59:48 25 4
gpt4 key购买 nike

在搜索了将近 4 天以找到解决我问题的方法之后,我现在向您求助,希望得到帮助。

我有一个只有一个 UIViewContainerUIViewController。该容器将以编程方式填充从 nib 文件加载的 View 。最后一个 View 附有 3 个手势识别器。但是他们都没有被击中。

带有 ViewContainer 的主视图

enter image description here

nib View

enter image description here

将 view.nib 加载到容器中的代码

userMasterViewContainer *container = [[[[NSBundle mainBundle] loadNibNamed:@"UserCardView" owner:nil options:nil] lastObject] initWithDelegate:self andUser:user];
[self.viewContainer addSubview:container];

nib View 类中的手势识别器代码

- (void)addGestureRecognizerToPicture:(UIView *)picture
{
// profile picture gestures
UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotatePicture:)];
[picture addGestureRecognizer:rotationGesture];

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePicture:)];
[pinchGesture setDelegate:self];
[picture addGestureRecognizer:pinchGesture];

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panPicture:)];
[panGesture setMaximumNumberOfTouches:2];
[panGesture setDelegate:self];
[picture addGestureRecognizer:panGesture];

self.userInteractionEnabled = YES;
}

- (void)rotatePicture:(id)rotateProfilePicture
{

}

- (void)scalePicture:(id)scaleProfilePicture
{

}

- (void)panPicture:(UIPanGestureRecognizer *)gestureRecognizer
{

}

手势将在 viewDidLoad 中添加到两个 UIImageView:Cover OverlayUser Photo

[self addGestureRecognizerToPicture:self.backgroundPicture];

他们都没有工作。我希望有人能帮助我。

最好的问候安德烈

最佳答案

又试了几天,问题解决了。有一种奇怪的父 View 组合捕获了我的用户交互。

我通过将每个不应识别触摸的 View 的 userInteractionEnabled 属性设置为 NO 来解决此问题。

// setup inactive and active elements for user interactions
self.userInteractionEnabled = YES;
self.userPicture.userInteractionEnabled = YES;
self.buttonOverlay.userInteractionEnabled = NO;
self.backgroundPictureOverlay.userInteractionEnabled = NO;
self.userPictureOverlay.userInteractionEnabled = NO;

因为还有一个 UIButton Button - Profile 覆盖在我的 View 上。还需要以下代码来防止他捕捉到手势。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return touch.view == self.buttonOverlay ? NO : YES;
}

此外,我必须添加以下方法,因为我想在简单的图像编辑器中使用这些手势。使用此代码,我可以同时旋转、缩放和平移。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

关于ios - 嵌入式 ViewContainer 中的手势识别器不会被击中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25412452/

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