我有两个简单的 UIViewController,它们的 View 是 320 x 460,带有状态栏。我在 AppDelegate 中做
self.window.rootViewController = [[[SimpleController alloc] init] autorelease];
[self.window makeKeyAndVisible];
在 SimpleController 中我有一个按钮
- (IBAction) switchToVerySimpleController
{
[UIView transitionWithView: [[UIApplication sharedApplication] keyWindow]
duration: 0.5
options: UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = [[[VerySimpleController alloc] init] autorelease]; }
completion: NULL];
}
新 View (VerySimpleController.view) 填充了蓝色。动画完成后,新 View 会在底部显示一条白色细条纹(状态栏大小),然后跳入到位。为什么会发生这种情况以及如何避免这种情况?我想应该归咎于它的状态栏,我尝试在 IB 中为两个 View 设置 statusBar = Unspecified,但它没有帮助。
更新: 当我从一开始就隐藏 statusBar(通过 .info 文件中的设置)时,不会进行 View 调整。但是仍然...我需要显示 statusBar 并且我需要该动画正常工作。
最佳答案
当一个 rootViewController 被分配给一个窗口时,a new frame is assigned如果存在状态栏,则显示到 rootViewController 的 View 。这样 rootViewController 的 View 不会隐藏在状态栏下。
由于您是在动画 block 内设置窗口的 rootViewController,因此新的帧分配也会被动画化。
要不显示跳转,您可以在动画之前设置 rootViewController View 的框架,如下所示:
- (IBAction) switchToVerySimpleController
{
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
VerySimpleController *vsc = [[[VerySimpleController alloc] init] autorelease];
vsc.view.frame = CGRectMake(vsc.frame.origin.x,
statusBarFrame.size.height,
vsc.frame.size.width,
vsc.frame.size.height);
[UIView transitionWithView: [[UIApplication sharedApplication] keyWindow]
duration: 0.5
options: UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = vsc }
completion: NULL];
}
关于ios - 当我将它作为 subview (通过 rootViewController 属性)添加到 UIWindow 并进行翻转时, View 为 “jumping”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5830670/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我需要从一个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=>
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
我有一个具有一些属性的模型: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
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我有这个html标记:我想得到这个:我如何使用Nokogiri做到这一点? 最佳答案 require'nokogiri'doc=Nokogiri::HTML('')您可以通过xpath删除所有属性:doc.xpath('//@*').remove或者,如果您需要做一些更复杂的事情,有时使用以下方法遍历所有元素会更容易:doc.traversedo|node|node.keys.eachdo|attribute|node.deleteattributeendend 关于ruby-Nokog