
- MainWindow (0,768,1024) - MainVIEw (0,80) - containervIEw (500,40,120,80) - subvIEw (500,80) -some buttons
我的问题是子视图的底部位于MainVIEw的边界之外.子视图底部的按钮没有响应.顶部的那个是响应式的,因为它们的位置也在MainvIEw内部.
因此,当我尝试单击子视图底部的按钮时,我实际上点击了MainWindow!子视图底部按钮的位置不在MainVIEw内部
有没有办法让我的所有子视图都可用,即使它的一半在MainVIEw界限之外?
我知道我可以直接在MainWindow下创建子视图,但我不想重做我的代码.
更新
这里如何设计我的观点:
A = MainWindow,B = MainVIEw,C =容器视图,D =子视图,X =我要点击的位置
+----------------------------+|A ||+-------------------------+ |||B | ||| +----------+ | ||+------------|C&D |-+ || |X | || +----------+ |+----------------------------+
谢谢
解决方法 您需要在MainVIEw中实现hitTest:(CGPoint)指向withEvent:(UIEvent *)事件.See the documentation
Points that lIE outsIDe the receiver’s bounds are never reported as
hits,even if they actually lIE within one of the receiver’s subvIEws.
SubvIEws may extend visually beyond the bounds of their parent if the
parent vIEw’s clipsToBounds property is set to NO. However,hit
testing always ignores points outsIDe of the parent vIEw’s bounds.
发表评论:
你应该继承UIVIEw.然后将nib中的MainVIEw类设置为UIVIEw子类.
Some hittesting is discussed here,但我无法找到它的工作原理.
Try this StackOverflow question
我没有测试过,但以下代码可能会满足您的需求:
- (UIVIEw*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{ for(UIVIEw *subvIEw in self.subvIEws) { UIVIEw *vIEw = [subvIEw hitTest:[self convertPoint:point toVIEw:subvIEw] withEvent:event]; if(vIEw) return vIEw; } return [super hitTest:point withEvent:event];} 总结 以上是内存溢出为你收集整理的iphone – 如何在他的父uiview之外部分访问uiview子视图?全部内容,希望文章能够帮你解决iphone – 如何在他的父uiview之外部分访问uiview子视图?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)