gpt4 book ai didi

ios - 在 UIView2 上方显示 UIView1,但按输入方式将 UIView2 置于 UIView1 上方

转载 作者:行者123 更新时间:2023-12-01 22:36:31 26 4
gpt4 key购买 nike

这是一个奇怪的场景,但我有两个重叠的 UIView,我需要将一个显示在另一个之上,但在接收输入时优先考虑较低的一个。如果那有意义的话。如果需要的话我可以澄清。

我最好在 Interface Builder 中执行此操作,但假设这是不可能的,有没有办法以编程方式执行此操作?

编辑:让它工作了,感谢@jaydee3。只需重写 UIView1 的 hitTest: 方法,如下所示。 UIView2 是 self.otherView。

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (self.otherView && [self.otherView pointInside:[self.otherView convertPoint:point fromView:self] withEvent:event])
{
return [self.otherView hitTest:[self.otherView convertPoint:point fromView:self] withEvent:event];
}

return [super hitTest:point withEvent:event];
}

最佳答案

如果您不需要在 view1 上输入内容,只需设置 view1.userInteractionEnabled = NO。这可以在 IB 中完成。

否则,您必须使用一些代码。例如。 view1 的子类 UIView 并重写 hitTest: ... 方法。如果触摸点与另一个 View 重叠,则返回[view2 hitTest: …]

关于ios - 在 UIView2 上方显示 UIView1,但按输入方式将 UIView2 置于 UIView1 上方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11479765/

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