我正在尝试在点击链接时从右边框将 UIWebView 动画化到屏幕上。为此,我使用了两个 UIView。一个称为 onScreenWebView,另一个称为 offScreenWebView。我的想法是,我可以将 offscreenWebView 从右侧动画化到屏幕上,并将 onScreenWebView 动画化到离开屏幕到左侧。然后交换 View (因此屏幕上的 View 变为 onScreenWebView,反之亦然)但我的动画有问题。我必须指出,它在第一次使用时效果很好。之后,它根本无法正常工作。
View 是这样对齐的
__________ __________
| | | |
| on | | off |
| screen | | screen |
|________| |________|
这是动画代码:
offScreenWebView.hidden = true;
offScreenWebView.frame = self.frame;
[offScreenWebView offSetX:self.bounds.size.width + kOffsetPadding]; // move offscreen to the right
[self logWebRects:@"begin"];
offScreenWebView.hidden = false;
[self bringSubviewToFront:offScreenWebView];
[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationCurveEaseInOut animations:^{
[self logWebRects:@"during 1"];
offScreenWebView.frame = self.frame;
onScreenWebView.frame = CGRectMake(-(self.bounds.size.width + kOffsetPadding), 0, onScreenWebView.bounds.size.width, onScreenWebView.bounds.size.height);
[self logWebRects:@"during 2"];
}completion:^(BOOL finished) {
[self logWebRects:@"finished b4 swap"];
[self swapWebViews];
[self logWebRects:@"finished -- done"];
}];
这是我的 logWebRects 方法的输出(只是每个 View 的来源)
Navigation Type :: Link Clicked
Rect of self frame :: {{0, 0}, {320, 460}}
99 -- Point of offscreen origin begin :: {335, 0}
0 -- Point of onscreen origin begin :: {0, 0}
99 -- Point of offscreen origin during 1 :: {335, 0}
0 -- Point of onscreen origin during 1 :: {0, 0}
99 -- Point of offscreen origin during 2 :: {0, 0}
0 -- Point of onscreen origin during 2 :: {-335, 0}
Navigation Type :: Other
99 -- Point of offscreen origin finished b4 swap :: {0, 0}
0 -- Point of onscreen origin finished b4 swap :: {-335, 0}
0 -- Point of offscreen origin finished -- done :: {-335, 0}
99 -- Point of onscreen origin finished -- done :: {0, 0}
Navigation Type :: Link Clicked
Rect of self frame :: {{0, 0}, {320, 460}}
0 -- Point of offscreen origin begin :: {335, 0}
99 -- Point of onscreen origin begin :: {0, 0}
0 -- Point of offscreen origin during 1 :: {335, 0}
99 -- Point of onscreen origin during 1 :: {0, 0}
0 -- Point of offscreen origin during 2 :: {0, 0}
99 -- Point of onscreen origin during 2 :: {-335, 0}
Navigation Type :: Other
0 -- Point of offscreen origin finished b4 swap :: {335, 0}
99 -- Point of onscreen origin finished b4 swap :: {0, 0}
99 -- Point of offscreen origin finished -- done :: {0, 0}
0 -- Point of onscreen origin finished -- done :: {335, 0}
这些日志来自初始运行。然后也是第二轮。您会注意到,无论出于何种原因,动画 block 都会在完成 block 之前重置每个 Web View 的框架。
我应该注意,我使用经典的临时变量交换来交换 Web View 。此外,它们是兄弟 View 。
最佳答案
我知道这有点老了,但我遇到了同样的问题,这是我找到的唯一关于它的帖子。
问题是 bringSubviewToFront 执行隐式动画(我猜)阻止动画 block 分配正确的帧。
我通过禁用隐式动画解决了这个问题。 尝试使用这段代码代替普通的 bringSubviewToFront。
[CATransaction begin];
[CATransaction setDisabledActions:YES];
[self bringSubviewToFront:offScreenWebView];
[CATransaction commit];
关于ios - UIView 动画将 View 重置为原始矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11838209/
我需要从一个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=>
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi
Unity自动旋转动画1.开门需要门把手先动,门再动2.关门需要门先动,门把手再动3.中途播放过程中不可以再次进行操作觉得太复杂?查看我的文章开关门简易进阶版效果:如果这个门可以直接打开的话,就不需要放置"门把手"如果门把手还有钥匙需要旋转,那就可以把钥匙放在门把手的"门把手",理论上是可以无限套娃的可调整参数有:角度,反向,轴向,速度运行时点击Test进行测试自己写的代码比较垃圾,命名与结构比较拉,高手轻点喷,新手有类似的需求可以拿去做参考上代码usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;u
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
除了可访问性标准不鼓励使用这一事实指向当前页面的链接,我应该怎么做重构以下View代码?#navigation%ul.tabbed-ifcurrent_page?(new_profile_path)%li{:class=>"current_page_item"}=link_tot("new_profile"),new_profile_path-else%li=link_tot("new_profile"),new_profile_path-ifcurrent_page?(profiles_path)%li{:class=>"current_page_item"}=link_tot("p