我的 iPhone 应用程序支持颠倒的界面方向: 当用户将手机上下颠倒(使主页按钮位于顶部)时,整个用户界面将垂直翻转。
但是,当尝试从我的 View Controller A 中呈现一些 View Controller B 时出现问题(在此示例中,我呈现标准邮件编辑器 View Controller ):
- (IBAction)buttonTapped:(id)sender {
MFMailComposeViewController *mailVC = [MFMailComposeViewController new];
mailVC.mailComposeDelegate = self;
[self presentViewController:mailVC animated:YES completion:nil];
}
当触发此方法时,首先发生的事情是(蓝色) View Controller A 出于某种原因立即垂直翻转而没有动画(如第一个屏幕截图所示)→ 为什么?
接下来,呈现的 View Controller B 从底部移入 View (正如它应该的那样)。
当关闭 View Controller B 时,它会立即翻转并移出 View 到顶部(而不是它来自的方向,如第二个屏幕截图所示)。
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissModalViewControllerAnimated:YES];
}
这是 iOS 中的错误还是我如何避免这种奇怪的行为?
(我只需要与正常纵向模式相同的标准动画来呈现 View Controller - 没有这些翻转。)
最佳答案
我猜 MFMailComposeViewController 不支持颠倒的界面方向,这就是为什么它可以被解释为错误。 但是 Apple 建议不要为 iPhone 应用程序使用颠倒的界面方向。其主要原因可以通过这样的例子来解释:
这不是用户友好的体验。
我会考虑在您的网站上使用颠倒的方向。
然而,如果使用颠倒的界面方向是必需的条件,那么你可以使用这样的技巧:
为 MFMailComposeViewController 创建类别并覆盖方法 supportedInterfaceOrientations 以允许支持必要的方向并将其导入到创建了 MFMailComposeViewController 的类:
// MFMailComposeViewController+Orientation.h file
#import <MessageUI/MessageUI.h>
@interface MFMailComposeViewController (Orientation)
@end
// MFMailComposeViewController+Orientation.m file
#import "MFMailComposeViewController+Orientation.h"
@implementation MFMailComposeViewController (Orientation)
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
@end
注意:我不确定这个技巧是否会通过 Apple application approving center 重写类别中的现有方法。
关于ios - 当界面方向颠倒时呈现 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23249252/
这里有一个很好的答案解释了如何在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”结果的
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我是HanamiWorld的新人。我已经写了这段代码:moduleWeb::Views::HomeclassIndexincludeWeb::ViewincludeHanami::Helpers::HtmlHelperdeftitlehtml.headerdoh1'Testsearchengine',id:'title'hrdiv(id:'test')dolink_to('Home',"/",class:'mnu_orizontal')link_to('About',"/",class:'mnu_orizontal')endendendendend我在模板上调用了title方法。htm
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#
我有一个用Rails3编写的站点。我的帖子模型有一个名为“内容”的文本列。在帖子面板中,html表单使用tinymce将“content”列设置为textarea字段。在首页,因为使用了tinymce,post.html.erb的代码需要用这样的原始方法来实现。.好的,现在如果我关闭浏览器javascript,这个文本区域可以在没有tinymce的情况下输入,也许用户会输入任何xss,比如alert('xss');.我的前台会显示那个警告框。我尝试sanitize(@post.content)在posts_controller中,但sanitize方法将相互过滤tinymce样式。例如
当我尝试使用“套接字”库中的方法“read_nonblock”时出现以下错误IO::EAGAINWaitReadable:Resourcetemporarilyunavailable-readwouldblock但是当我通过终端上的IRB尝试时它工作正常如何让它读取缓冲区? 最佳答案 IgetthefollowingerrorwhenItrytousethemethod"read_nonblock"fromthe"socket"library当缓冲区中的数据未准备好时,这是预期的行为。由于异常IO::EAGAINWaitReadab
当我将我的Rails+React应用程序部署到Heroku时,我遇到了问题。React客户端位于Rails应用程序的client/目录中。由于使用了react-router,Rails服务器需要知道从React构建中渲染index.html。当我在Heroku上部署客户端时,脚本将内容从client/build/.复制到Rails应用程序的public/目录。现在问题来了:当我的路由检测到类似example.com/about的路径时,它会尝试呈现public/index.html。方法如下:deffallback_index_htmlrenderfile:"public/index.
我试图让嵌套评论在Rails5应用程序中正常工作,但遇到了很多困难。我正在构建一个问答网站,我有一个Acomment模型,其中有属于答案的评论,还有属于其他评论的评论:classAcomment我想显示所有评论,然后显示所有对评论的回复,以及对回复的回复等。但是我不知道如何使嵌套正常工作。在我看来,在每个循环中,我正在渲染_comment.html.erb部分:"comment",:object=>comment%>然后,在我的_comment.html.erb局部中,我显示评论、回复链接,然后呈现评论回复的局部:comment,:answer_id=>comment.answer)i