我在这个线程中描述了一个类似的问题:Capturing touches on a subview outside the frame of its superview using hitTest:withEvent:
情况
我们正在 Xamarin iOS 中开发应用程序。我们有一个自定义 View 来创建自己的自动完成输入字段,其中包含一个 UiTextField 和一个 UiTableView,用于显示结果。
为了实现更好的模块化,我们有另一个名为 LabeledContainer 的自定义 View 。在其中,我可以设置一个标签并将内容添加到底部 View ,在本例中是自动完成。
AutoComplete LabeledContainer
+---------------+ +---------------+
| UiView | | UiView |
|+-------------+| |+-------------+|
|| UiTextField || || UiLabel ||
|+-------------+| |+-------------+|
|+-------------+| |+-------------+|
|| UiTableView || || UiView ||
|+-------------+| |+-------------+|
+---------------+ +---------------+
The following gets rendered:
MAINVIEW
+------------------------------+
| |
| |
| |
| |
|+----------------------------+|
|| LabeledContainer ||
||+--------------------------+||
||| Label |||
||+--------------------------+||
||+--------------------------+||
||| Content |||
|||+------------------------+|||
|||| AutoComplete ||||
|||+------------------------+|||
||+--------------------------+||
|+----------------------------+|
| |
| |
| |
| |
+------------------------------+
问题
我在使用“hitarea”时遇到问题,因为自动完成下拉列表 (tableView) 在自定义 View 框架之外。框架仅采用输入字段的高度,下拉菜单在底部与它重叠。所以我添加了以下方法来将下拉列表添加到 hitArea。
public override bool PointInside(CGPoint point, UIEvent uievent)
{
var bounds = Bounds;
bounds.Height += DROPDOWN.Bounds.Height;
return bounds.Contains(point);
}
但这只有在我将自动完成添加为 mainView 的 subChild 时才有效,因为 PointInside 会在那里被触发。如果我将 autoComplete 添加到 labeledContainer,之后它的框架高度为标签 + 自动完成的输入字段,则永远不会触发 PointsInside 方法。出现这种情况是因为 labeledContainer 不够高吧?那么当 superView 被触摸时, View 的 PointsInside 就会被触发?但我无法将 labeledContainer 或 autoComplete 设置得更高,以防止推送其他 View 。
我尝试将 PointsInside 方法也添加到 labeledContainer,但它没有解决我的问题,因为它没有触及 labeledContainer 框架并且从未调用过 autoComplete PointsInside。
最佳答案
默认情况下,UIView 不会接收其父 View 之外的触摸事件。但是,您可以将容器 View 子类化以检测其框架之外的触摸。容器 View 应将未处理的触摸事件转发到其 subview 。
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
CGPoint pointForTargetView = [self.autoCompleteView convertPoint:point fromView:self];
if (CGRectContainsPoint(self.autoCompleteView.bounds, pointForTargetView)) {
return [self.autoCompleteView hitTest:pointForTargetView withEvent:event];
}
return [super hitTest:point withEvent:event];
}
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. This can occur if the current view’s clipsToBounds property is set to NO and the affected subview extends beyond the view’s bounds.
关于ios - 捕获其父 View 框架外的 subview 上的触摸(在多个层上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42928594/
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2
我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que