【问题标题】:Switching content of 2 UIWebViews切换2个UIWebViews的内容
【发布时间】:2012-05-23 07:46:12
【问题描述】:

在我的应用程序中,我有一个滚动视图,其中包含多个 web 视图(我只使用 3 个 web 视图进行无限滚动之类的操作)...为了做到这一点,我需要切换 2 个 web 视图的内容(类似于将一个 web 视图复制到另一个可能吗?)...这不能仅通过将 htmlString 从一个 webView 加载到另一个 webView 来完成...

有什么想法吗?提前非常感谢

编辑:代码与本教程非常相似:http://mobiledevelopertips.com/user-interface/creating-circular-and-infinite-uiscrollviews.html

【问题讨论】:

  • 你有任何你尝试过的代码吗?为什么不能通过将htmlString从一个加载到另一个来完成?
  • 我添加了一些对我的代码的引用......查看 pposthoorn 在该页面上的评论 - 他解释了为什么不能仅通过加载 html 字符串来完成 - 页面真的闪烁......
  • 我在无限网络视图上遇到了同样的问题。你解决问题了吗?怎么做?谢谢。

标签: ios uiwebview uiscrollview copy


【解决方案1】:

如果有人关心我已经解决了这个问题,只需将 uiwebvies 添加到一个可变数组中,然后首先在滚动视图中切换它们(可见),然后再将它们切换到该可变数组中(逻辑上)。在上面链接的示例中,“向右滚动”的代码看起来像这样(在 scrollViewDidEndDecelerating 中:):

         CGRect frame = ((UIView*)[self.arrWebViewsContent objectAtIndex:2]).frame;
        ((UIView*)[self.arrWebViewsContent objectAtIndex:2]).frame = ((UIView*)[self.arrWebViewsContent objectAtIndex:1]).frame;
        ((UIView*)[self.arrWebViewsContent objectAtIndex:1]).frame = ((UIView*)[self.arrWebViewsContent objectAtIndex:0]).frame;
        ((UIView*)[self.arrWebViewsContent objectAtIndex:0]).frame = frame;

        UIView *view_tmp = [self.arrWebViewsContent objectAtIndex:0];
        [self.arrWebViewsContent replaceObjectAtIndex:0 withObject:[self.arrWebViewsContent objectAtIndex:1]];
        [self.arrWebViewsContent replaceObjectAtIndex:1 withObject:[self.arrWebViewsContent objectAtIndex:2]];
        [self.arrWebViewsContent replaceObjectAtIndex:2 withObject:view_tmp];

【讨论】:

  • 你能提供更多关于你成功的示例代码吗?谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-05
  • 1970-01-01
相关资源
最近更新 更多