<legend id='Yl5hh'><style id='Yl5hh'><dir id='Yl5hh'><q id='Yl5hh'></q></dir></style></legend>
        • <bdo id='Yl5hh'></bdo><ul id='Yl5hh'></ul>

        <i id='Yl5hh'><tr id='Yl5hh'><dt id='Yl5hh'><q id='Yl5hh'><span id='Yl5hh'><b id='Yl5hh'><form id='Yl5hh'><ins id='Yl5hh'></ins><ul id='Yl5hh'></ul><sub id='Yl5hh'></sub></form><legend id='Yl5hh'></legend><bdo id='Yl5hh'><pre id='Yl5hh'><center id='Yl5hh'></center></pre></bdo></b><th id='Yl5hh'></th></span></q></dt></tr></i><div id='Yl5hh'><tfoot id='Yl5hh'></tfoot><dl id='Yl5hh'><fieldset id='Yl5hh'></fieldset></dl></div>

      1. <small id='Yl5hh'></small><noframes id='Yl5hh'>

        <tfoot id='Yl5hh'></tfoot>

      2. 使用 AsyncDisplayKit 添加自定义按钮

        Add custom Button with AsyncDisplayKit(使用 AsyncDisplayKit 添加自定义按钮)

          <bdo id='USP3Q'></bdo><ul id='USP3Q'></ul>
            <legend id='USP3Q'><style id='USP3Q'><dir id='USP3Q'><q id='USP3Q'></q></dir></style></legend>

              <small id='USP3Q'></small><noframes id='USP3Q'>

                <tbody id='USP3Q'></tbody>
                <tfoot id='USP3Q'></tfoot>

                1. <i id='USP3Q'><tr id='USP3Q'><dt id='USP3Q'><q id='USP3Q'><span id='USP3Q'><b id='USP3Q'><form id='USP3Q'><ins id='USP3Q'></ins><ul id='USP3Q'></ul><sub id='USP3Q'></sub></form><legend id='USP3Q'></legend><bdo id='USP3Q'><pre id='USP3Q'><center id='USP3Q'></center></pre></bdo></b><th id='USP3Q'></th></span></q></dt></tr></i><div id='USP3Q'><tfoot id='USP3Q'></tfoot><dl id='USP3Q'><fieldset id='USP3Q'></fieldset></dl></div>

                  本文介绍了使用 AsyncDisplayKit 添加自定义按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发一个 IOS 应用程序.我使用 Facebook AsyncDisplayKit 库.我想在 ASNodeCell 中添加一个按钮 我得到变量‘节点’在被块捕获时未初始化.如何在 ASNodeCell 中添加 UIButton 或 UIWebView 控件.请帮助我

                  I am developing an IOS application. I use Facebook AsyncDisplayKit library. I want to a button in ASNodeCell Bu I got "Variable 'node' is uninitialized when captured by block. How can I add UIButton or UIWebView control in ASNodeCell. Please help me

                  dispatch_queue_t _backgroundContentFetchingQueue;
                      _backgroundContentFetchingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
                  
                  dispatch_async(_backgroundContentFetchingQueue, ^{
                      ASDisplayNode *node = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
                          UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
                          [button sizeToFit];
                          node.frame = button.frame;
                          return button;
                      }];
                  
                                             // Use `node` as you normally would...
                      node.backgroundColor = [UIColor redColor];
                  
                      [self.view addSubview:node.view];
                  });
                  

                  推荐答案

                  请注意,在您的情况下不需要使用 UIButton,您可以使用 ASTextNode 作为按钮,因为它继承自 ASControlNode(ASImageNode 也是如此).这在指南第一页的底部有描述:http://asyncdisplaykit.org/guide/.这也将允许您在后台线程而不是主线程上进行文本大小调整(您在示例中提供的块在主队列上执行).

                  Note that in your case there's no need to use UIButton, you can use ASTextNode as a button since it inherits from ASControlNode (same goes for ASImageNode). This is described at the bottom of the first page of the guide: http://asyncdisplaykit.org/guide/. That will also allow you to do the text sizing on the background thread instead of the main thread (the block you provide in your example is executed on the main queue).

                  为了完整起见,我还将评论您提供的代码.

                  For completeness I'll also comment on the code you provided.

                  您在创建块时尝试在块中设置节点的框架,因此您在初始化期间尝试在其上设置框架.这会导致你的问题.我认为您在使用 initWithViewBlock 时实际上不需要在节点上设置框架:因为在内部 ASDisplayNode 使用该块直接创建其 _view 属性,该属性最终添加到视图层次结构中.

                  You're trying to set the frame of the node in the block when you're creating it, so you're trying to set the frame on it during its initialization. That causes your problem. I don't think you actually need to set the frame on the node when you're using initWithViewBlock: because internally ASDisplayNode uses the block to directly create its _view property which is added to the view hierarchy in the end.

                  我还注意到您正在从后台队列调用 addSubview:,您应该始终在调用该方法之前将其分派回主队列.为方便起见,AsyncDisplayKit 还向 UIView 添加了 addSubNode:.

                  I also noticed you're calling addSubview: from the background queue, you should always dispatch back to the main queue before you call that method. AsyncDisplayKit also adds addSubNode: to UIView for convenience.

                  我已更改您的代码以反映更改,但我建议您在此处使用 ASTextNode.

                  I've changed you're code to reflect the changes though I recommend you use ASTextNode here.

                  dispatch_queue_t _backgroundContentFetchingQueue;
                  _backgroundContentFetchingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
                  
                  dispatch_async(_backgroundContentFetchingQueue, ^{
                  ASDisplayNode *node = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
                      UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
                      [button sizeToFit];
                      //node.frame = button.frame; <-- this caused the problem
                      return button;
                  }];
                  
                                         // Use `node` as you normally would...
                  node.backgroundColor = [UIColor redColor];
                  
                  // dispatch to main queue to add to view
                  dispatch_async(dispatch_get_main_queue(),
                      [self.view addSubview:node.view];
                      // or use [self.view addSubnode:node];
                    );
                  });
                  

                  这篇关于使用 AsyncDisplayKit 添加自定义按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Published App on Play Store can#39;t communicate with Google Maps API and Facebook API(Play Store 上发布的应用程序无法与 Google Maps API 和 Facebook API 通信)
                  iOS UIWebView app opens link in Safari(iOS UIWebView 应用在 Safari 中打开链接)
                  Close UIWebView using javascript:window.close();(使用 javascript:window.close() 关闭 UIWebView;)
                  NSCachedURLResponse returns object, but UIWebView does not interprets content(NSCachedURLResponse 返回对象,但 UIWebView 不解释内容)
                  Trouble hiding iAd banner and displaying UIWebView in its place(无法隐藏 iAd 横幅并在其位置显示 UIWebView)
                  Knowing when AJAX has loaded in UIWebView(知道何时在 UIWebView 中加载了 AJAX)

                    <legend id='OheVa'><style id='OheVa'><dir id='OheVa'><q id='OheVa'></q></dir></style></legend>
                      <tbody id='OheVa'></tbody>

                    1. <i id='OheVa'><tr id='OheVa'><dt id='OheVa'><q id='OheVa'><span id='OheVa'><b id='OheVa'><form id='OheVa'><ins id='OheVa'></ins><ul id='OheVa'></ul><sub id='OheVa'></sub></form><legend id='OheVa'></legend><bdo id='OheVa'><pre id='OheVa'><center id='OheVa'></center></pre></bdo></b><th id='OheVa'></th></span></q></dt></tr></i><div id='OheVa'><tfoot id='OheVa'></tfoot><dl id='OheVa'><fieldset id='OheVa'></fieldset></dl></div>

                      <tfoot id='OheVa'></tfoot>

                        <small id='OheVa'></small><noframes id='OheVa'>

                          <bdo id='OheVa'></bdo><ul id='OheVa'></ul>