标签: nested

如何从UIScrollView窃取触摸?

今天,在我的创作时间,我做了一些非常全面的研究,如何从UIScrollView窃取触摸并立即将它们发送到特定的子视图,同时保持其余滚动视图的默认行为.考虑在UITableView中使用UIPickerView.默认行为是,如果您将手指拖到选择器视图上,滚动视图将滚动,选择器视图将保持不变.

我尝试的第一件事是覆盖

- (BOOL)touchesShouldCancelInContentView:(UIView *)view
Run Code Online (Sandbox Code Playgroud)

并且根本不允许UIScrollView取消选择器视图内的触摸.这有效,但它有一个令人不快的副作用.您希望选择器视图立即响应,因此您必须设置delaysContentTouches为NO.问题是您不希望表视图的其余部分立即响应,因为如果确实如此,表视图单元将始终在滚动开始之前突出显示几毫秒.

我尝试的第二件事是覆盖

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
Run Code Online (Sandbox Code Playgroud)

因为我已经读过滚动视图总是返回自己,所以它会"窃取"其子视图中的触摸,然后如果它们对滚动视图不感兴趣则将它们发送到子视图.但是,这不再适用.UIScrollView的hitTest的默认实现:withEvent:实际上返回应该接收触摸的子视图.相反,它使用手势识别器来拦截触摸.

所以我尝试的第三件事就是实现我自己的手势识别器,如果触摸在选择器视图之外,则会导致失败,否则会成功.然后我将所有滚动视图的手势识别器设置为失败,除非我的手势识别器使用以下代码失败:

for (UIGestureRecognizer * gestureRecognizer in self.tableView.gestureRecognizers)
{
    [gestureRecognizer requireGestureRecognizerToFail:myRecognizer];
}
Run Code Online (Sandbox Code Playgroud)

事实上这实际上是从滚动视图中窃取了触摸,但是拾取器视图从未接收到它们.所以我可能只是发送我的手势识别器使用此代码接收的所有触摸:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch *touch in touches)
        [touch.view touchesBegan:touches withEvent:event];
}
Run Code Online (Sandbox Code Playgroud)

以上代码是简化版.我还确保视图是一个选择器视图(或其中一个子视图),并为上面提到的手势识别器设置适当的状态.我也做了同样的取消,结束和感动.但是,选择器视图仍然没有响应.

在回到我的日常工作之前,我还尝试了最后一件事.在我广泛的谷歌搜索过程中,我读到嵌套的UIScrollViews从3.x开始就神奇地工作了,所以我尝试将我的选择器视图放在嵌套的UIScrollView中并在其上设置以下属性:

scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = NO;
Run Code Online (Sandbox Code Playgroud)

正如人们所期望的那样,外部滚动视图不会处理内部滚动视图与处理选择器视图时的任何不同,因此内部滚动视图没有接收到触摸.我认为这是一个很长的镜头,但它很容易实现,所以我认为值得一试.

我所知道的是UIScrollView有一个名为UIScrollViewDelayedTouchesBeganGestureRecognizer截取触摸的手势识别器,并在150(?)ms之后将它们发送到适当的子视图.我想我应该能够写一个类似的识别器,导致滚动视图的默认识别器失败,而不是延迟触摸立即将它们发送到选择器视图.因此,如果有人知道如何编写这样的识别器,请告诉我,如果您有任何其他问题的解决方案,那么您也非常欢迎.

感谢您阅读整个问题,即使您不知道答案,您仍然可以提出问题,以便得到更多关注(希望能得到答案的人).谢谢!:)

iphone nested uiscrollview uipickerview ios4

38
推荐指数
1
解决办法
2万
查看次数

PHP foreach与嵌套数组?

我有一个嵌套数组,我想在其中显示结果的子集.例如,在下面的数组中,我想循环遍历嵌套数组[1]中的所有值.

Array
(
  [0] => Array
    (
      [0] => one
      [1] => Array
        (
          [0] => 1
          [1] => 2
          [2] => 3
        )
    )

  [1] => Array
    (
      [0] => two
      [1] => Array
        (
          [0] => 4
          [1] => 5
          [2] => 6
        )
    )

  [2] => Array
    (
      [0] => three
      [1] => Array
        (
          [0] => 7
          [1] => 8
          [2] => 9
        )
    )
)

我试图使用foreach函数,但我似乎无法让它工作.这是我的原始语法(虽然我意识到这是错误的).

$tmpArray = array(array("one",array(1,2,3)),array("two",array(4,5,6)),array("three",array(7,8,9)));

foreach ($tmpArray[1] as $value) {
  echo …

php arrays foreach nested

37
推荐指数
2
解决办法
9万
查看次数

如何使用弹性搜索搜索嵌套对象

好吧,到目前为止我还没弄清楚这一点.希望有人可以提供一些见解.

鉴于以下文档,我如何搜索视频标题中包含"test"的视频的所有文档?我正在使用HTTP API. (基本上,你如何使用弹性搜索搜索嵌套对象?我知道那里必须有文档,但我真的找不到任何文档.)

[{
    id:4635,
    description:"This is a test description",
    author:"John",
    author_id:51421,
    video: {
        title:"This is a test title for a video",
        description:"This is my video description",
        url:"/url_of_video"
    }
},
{
    id:4636,
    description:"This is a test description 2",
    author:"John",
    author_id:51421,
    video: {
        title:"This is an example title for a video",
        description:"This is my video description2",
        url:"/url_of_video2"
    }
},
{
    id:4637,
    description:"This is a test description3",
    author:"John",
    author_id:51421,
    video: {
        title:"This is a test title for a video3",
        description:"This is …
Run Code Online (Sandbox Code Playgroud)

json nested elasticsearch

37
推荐指数
4
解决办法
6万
查看次数

嵌套列表理解有两个列表

我理解简单列表理解是如何工作的,例如:

[x*2 for x in range(5)] # returns [0,2,4,6,8]
Run Code Online (Sandbox Code Playgroud)

而且我也理解嵌套列表comprehesion的工作原理:

w_list = ["i_have_a_doubt", "with_the","nested_lists_comprehensions"]

# returns the list of strings without underscore and capitalized
print [replaced.title() for replaced in [el.replace("_"," ")for el in w_list]]
Run Code Online (Sandbox Code Playgroud)

所以,当我尝试这样做的时候

l1 = [100,200,300]
l2 = [0,1,2]
[x + y for x in l2 for y in l1 ]
Run Code Online (Sandbox Code Playgroud)

我期待这个:

[101,202,303]
Run Code Online (Sandbox Code Playgroud)

但我得到了这个:

[100,200,300,101,201,301,102,202,302]
Run Code Online (Sandbox Code Playgroud)

所以我有一个更好的方法解决问题,这给了我想要的东西

[x + y for x,y in zip(l1,l2)]
Run Code Online (Sandbox Code Playgroud)

但我不理解第一个代码上9个元素的返回

python nested list-comprehension

37
推荐指数
3
解决办法
5万
查看次数

嵌套的struct初始化文字

我怎样才能做到这一点:

type A struct {
    MemberA string
}

type B struct {
    A
    MemberB string
}
Run Code Online (Sandbox Code Playgroud)

...

b := B {
    MemberA: "test1",
    MemberB: "test2",
}
fmt.Printf("%+v\n", b)
Run Code Online (Sandbox Code Playgroud)

编译给我:"结构文字中的未知B字段'MemberA'"

当我提供像这样的文字结构成员值时,如何初始化MemberA(来自"父"结构)?

struct nested literals go

36
推荐指数
1
解决办法
1万
查看次数

WPF:如何绑定到嵌套属性?

我可以绑定到属性,但不能绑定到另一个属性中的属性.为什么不?例如

<Window DataContext="{Binding RelativeSource={RelativeSource Self}}"...>
...
    <!--Doesn't work-->
    <TextBox Text="{Binding Path=ParentProperty.ChildProperty,Mode=TwoWay}" 
             Width="30"/>
Run Code Online (Sandbox Code Playgroud)

(注意:我不是要做master-details或者其他任何东西.这两个属性都是标准的CLR属性.)

更新:问题是我的ParentProperty依赖于XAML中的一个对象被初始化.不幸的是,该对象后来在XAML文件中定义而不是Binding,因此当Binding读取ParentProperty时,该对象为null.由于重新排列XAML文件会搞砸布局,我能想到的唯一解决方案是在代码隐藏中定义Binding:

<TextBox x:Name="txt" Width="30"/>

// after calling InitializeComponent()
txt.SetBinding(TextBox.TextProperty, "ParentProperty.ChildProperty");
Run Code Online (Sandbox Code Playgroud)

wpf binding nested properties

35
推荐指数
2
解决办法
5万
查看次数

在包含任意数量的嵌套哈希和数组的哈希深处查找键/值对

Web服务返回一个包含未知数量的嵌套哈希的哈希,其中一些包含一个数组,该数组又包含未知数量的嵌套哈希值.

一些键不是唯一的 - 即存在于多个嵌套的哈希中.

但是,我真正关心的所有键都是独一无二的.

有没有什么事情我可以给顶级哈希一个关键,并且即使键值对深埋在这个泥潭里,也要回到它的价值?

(该网络服务是亚马逊产品广告API,它根据每个产品类别中允许的结果数量和搜索类型略微改变其提供的结果结构.)

ruby arrays hash amazon nested

35
推荐指数
6
解决办法
4万
查看次数

Django嵌套事务 - "with transaction.atomic()"

我想知道我是否有这样的事情:

def functionA():
    with transaction.atomic():
        #save something
        functionB()

def functionB():
    with transaction.atomic():
        #save another thing
Run Code Online (Sandbox Code Playgroud)

有人知道会发生什么吗?如果functionB失败,functionA也会回滚吗?

谢谢!

django transactions nested atomic

35
推荐指数
1
解决办法
1万
查看次数

Rails:如何修改嵌套资源的测试?

在学习Rails时,我创建了一个应用程序,其Domains控制器嵌套在Customers控制器下面.我正在使用Rails 2.3.4,这是一次学习经历.我设法得到以下路由设置:

    customer_domains GET    /customers/:customer_id/domains(.:format)          {:controller=>"domains", :action=>"index"}
                     POST   /customers/:customer_id/domains(.:format)          {:controller=>"domains", :action=>"create"}
 new_customer_domain GET    /customers/:customer_id/domains/new(.:format)      {:controller=>"domains", :action=>"new"}
edit_customer_domain GET    /customers/:customer_id/domains/:id/edit(.:format) {:controller=>"domains", :action=>"edit"}
     customer_domain GET    /customers/:customer_id/domains/:id(.:format)      {:controller=>"domains", :action=>"show"}
                     PUT    /customers/:customer_id/domains/:id(.:format)      {:controller=>"domains", :action=>"update"}
                     DELETE /customers/:customer_id/domains/:id(.:format)      {:controller=>"domains", :action=>"destroy"}
           customers GET    /customers(.:format)                               {:controller=>"customers", :action=>"index"}
                     POST   /customers(.:format)                               {:controller=>"customers", :action=>"create"}
        new_customer GET    /customers/new(.:format)                           {:controller=>"customers", :action=>"new"}
       edit_customer GET    /customers/:id/edit(.:format)                      {:controller=>"customers", :action=>"edit"}
            customer GET    /customers/:id(.:format)                           {:controller=>"customers", :action=>"show"}
                     PUT    /customers/:id(.:format)                           {:controller=>"customers", :action=>"update"}
                     DELETE /customers/:id(.:format)                           {:controller=>"customers", :action=>"destroy"}
                root        /                                                  {:controller=>"customers", :action=>"index"}
Run Code Online (Sandbox Code Playgroud)

但是,由于路由错误,域控制器的所有测试都会失败.

例如,以下测试(由Rails的资源生成器生成)失败,DomainsControllerTest类中的所有其他测试也失败.

class DomainsControllerTest …
Run Code Online (Sandbox Code Playgroud)

testing routing nested ruby-on-rails

34
推荐指数
1
解决办法
9781
查看次数

在Java中,当我不在内部类时,如何访问外部类?

如果我有一个内部类的实例,我如何从不在内部类中的代码访问外部?我知道在内部类中,我可以Outer.this用来获取外部类,但我找不到任何外部方法来获取它.

例如:

public class Outer {
  public static void foo(Inner inner) {
    //Question: How could I write the following line without
    //  having to create the getOuter() method?
    System.out.println("The outer class is: " + inner.getOuter());
  }
  public class Inner {
    public Outer getOuter() { return Outer.this; }
  }
}
Run Code Online (Sandbox Code Playgroud)

java syntax nested

32
推荐指数
4
解决办法
3万
查看次数