我认为这是解决从 UITableViewRowAction 启动弹出窗口的问题的一种相当聪明的方法,我想在目标操作上放置一个清晰的 UIView并将它用于 sourceRect 以锚定 UIPopoverPresentationController。在这种情况下,目标操作是下面屏幕截图中显示的橙色“Acct”按钮。
我在整个 tableview 上使用清晰的 UIView (self.clearTopView) 并使用以下命令初始化启动 View (tappedViewOverlay)从 View 中的点击位置 (point) 和 CGSize (tappedRectSize) 派生的框架(我认为是这样)。然后我将它作为 subview 添加到 self.clearTopView。我目前正在把它涂成黑色,这样我就可以找到它。
如下图所示,部分方案正在按计划进行。 tappedViewOverlay View 已添加,并适当着色。 popoverPresentationController (thisPPC) 按预期从此 View 启动。
问题是 View 总是位于屏幕的左上角,而不是所需的位置,即点击发生的位置。这是相关代码:
else if ([[segue identifier] isEqualToString:@"AccountPopSegue"])
{
UITapGestureRecognizer *tapGestureRecognizer;
CGPoint point = [tapGestureRecognizer locationInView:self.clearTopView];
NSString *pointString = NSStringFromCGPoint(point);
NSLog(@"point is located at %@",pointString);
CGSize tappedRectSize= CGSizeMake(60,60);
CGRect tappedRect = {point,tappedRectSize};
NSString * tappedRectString = NSStringFromCGRect(tappedRect);
NSLog(@"tappedRect = %@",tappedRectString);
tappedViewOverlay = [[UIView alloc]initWithFrame:tappedRect];
tappedViewOverlay.backgroundColor = [UIColor blackColor];
[self.clearTopView addSubview:tappedViewOverlay];
[self.clearTopView setUserInteractionEnabled:NO];
NSString *tappedOverlayFrame = NSStringFromCGRect(tappedViewOverlay.frame);
NSLog(@"tappedViewOverlay.frame = %@",tappedOverlayFrame);
UIViewController *controller = segue.destinationViewController;
controller.popoverPresentationController.delegate = self;
controller.preferredContentSize = CGSizeMake(320, 186);
UIPopoverPresentationController *thisPPC = controller.popoverPresentationController;
thisNavController = (UINavigationController *)segue.destinationViewController;
AccountChangeVC *acCVC = (AccountChangeVC *)thisNavController.topViewController;
acCVC.delegate = self;
thisPPC.sourceView = self.clearTopView;
thisPPC.sourceRect = tappedViewOverlay.bounds;
谁能告诉我哪里出错了?
编辑
CoderWang 指出了我的代码中的一个疏忽,所以我已经更正了它:
else if ([[segue identifier] isEqualToString:@"AccountPopSegue"])
{
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]init];
[self.clearTopView addGestureRecognizer:tapGestureRecognizer];
CGPoint point = [tapGestureRecognizer locationInView:self.clearTopView];
NSString *pointString = NSStringFromCGPoint(point);
NSLog(@"point is located at %@",pointString);
CGSize tappedRectSize= CGSizeMake(60,60);
CGRect tappedRect = {point,tappedRectSize};
NSString * tappedRectString = NSStringFromCGRect(tappedRect);
NSLog(@"tappedRect = %@",tappedRectString);
tappedViewOverlay = [[UIView alloc]initWithFrame:tappedRect];
tappedViewOverlay.backgroundColor = [UIColor blackColor];
[self.clearTopView addSubview:tappedViewOverlay];
[self.clearTopView setUserInteractionEnabled:NO];
NSString *tappedOverlayFrame = NSStringFromCGRect(tappedViewOverlay.frame);
NSLog(@"tappedViewOverlay.frame = %@",tappedOverlayFrame);
UIViewController *controller = segue.destinationViewController;
controller.popoverPresentationController.delegate = self;
controller.preferredContentSize = CGSizeMake(320, 186);
UIPopoverPresentationController *thisPPC = controller.popoverPresentationController;
thisNavController = (UINavigationController *)segue.destinationViewController;
AccountChangeVC *acCVC = (AccountChangeVC *)thisNavController.topViewController;
acCVC.delegate = self;
thisPPC.sourceView = self.clearTopView;
thisPPC.sourceRect = tappedViewOverlay.bounds;
此更改(tapGestureRecognizer 的初始化和添加到 self.clearTopView)会导致黑色 tappedViewOverlay View 的位置发生轻微变化.您可以在以下屏幕截图中看到它隐藏在“后退”导航按钮后面:
最佳答案
问题是'tappedRect'不正确,不知 Prop 体原因。 但是您可以尝试以下方法将“Acct”按钮的 rect 转换为 self.clearTopView :
CGRect tappedRect = [Acct.superview convertRect:acct.frame toView:self.clearTopView];
或转换为窗口(因为 self.clearTopView 覆盖了整个 tableview):
CGRect tappedRect = [Acct.superview convertRect:acct.frame toView:nil];
关于ios - 将 UIView 定位在点击点以启动弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38490169/
我的代码目前看起来像这样numbers=[1,2,3,4,5]defpop_threepop=[]3.times{pop有没有办法在一行中完成pop_three方法中的内容?我基本上想做类似numbers.slice(0,3)的事情,但要删除切片中的数组项。嗯...嗯,我想我刚刚意识到我可以试试slice! 最佳答案 是numbers.pop(3)或者numbers.shift(3)如果你想要另一边。 关于ruby-多次弹出/移动ruby数组,我们在StackOverflow上找到一
最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru
这里有一个很好的答案解释了如何在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”结果的
一、引擎主循环UE版本:4.27一、引擎主循环的位置:Launch.cpp:GuardedMain函数二、、GuardedMain函数执行逻辑:1、EnginePreInit:加载大多数模块int32ErrorLevel=EnginePreInit(CmdLine);PreInit模块加载顺序:模块加载过程:(1)注册模块中定义的UObject,同时为每个类构造一个类默认对象(CDO,记录类的默认状态,作为模板用于子类实例创建)(2)调用模块的StartUpModule方法2、FEngineLoop::Init()1、检查Engine的配置文件找出使用了哪一个GameEngine类(UGame
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
本文主要介绍在使用Selenium进行自动化测试或者任务时,对于使用了iframe的页面,如何定位iframe中的元素文章目录场景描述解决方案具体代码场景描述当我们在使用Selenium进行自动化测试的时候,可能会遇到一些界面或者窗体是使用HTML的iframe标签进行承载的。对于iframe中的标签,如果直接查找是无法找到的,会抛出没有找到元素的异常。比如近在咫尺的例子就是,CSDN的登录窗体就是使用的iframe,大家可以尝试通过F12开发者模式查看到的tag_name,class_name,id或者xpath来定位中的页面元素,会抛出NoSuchElementException异常。解决
我想用这两种语言中的任何一种(最好是ruby)制作一个窗口管理器。老实说,除了我需要加载某种X模块外,我不知道从哪里开始。因此,如果有人有线索,如果您能指出正确的方向,那就太好了。谢谢 最佳答案 XCB,X的下一代API使用XML格式定义X协议(protocol),并使用脚本生成特定语言绑定(bind)。它在概念上与SWIG类似,只是它描述的不是CAPI,而是X协议(protocol)。目前,C和Python存在绑定(bind)。理论上,Ruby端口只是编写一个从XML协议(protocol)定义语言到Ruby的翻译器的问题。生
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上
我想用Capistrano启动sidekiq。下面是代码namespace:sidekiqdotask:startdorun"cd#{current_path}&&bundleexecsidekiq-c10-eproduction-Llog/sidekiq.log&"pcapture("psaux|grepsidekiq|awk'{print$2}'|sed-n1p").strip!endend它执行成功但sidekiq仍然没有在服务器上启动。输出:$capsidekiq:starttriggeringloadcallbacks*2014-06-0315:03:01executing`