我认为这是解决从UITableViewRowAction
启动弹出窗口问题的一种相当聪明的方法,我想在目标操作上放置一个明确的UIView
并将其用于{ {1}}锚定sourceRect
。在这种情况下,目标操作是下面屏幕截图中显示的橙色“Acct”按钮。
我在整个tableview上使用了清晰的UIPopoverPresentationController
(UIView
),并使用从(我认为)位置派生的框架初始化启动视图(self.clearTopView
)视图中的点按(tappedViewOverlay
)和point
(CGSize
)。然后我将其作为子视图添加到tappedRectSize
。我现在把它着色为黑色所以我能找到它。
如下面的屏幕截图所示,该计划的一部分正在按计划运行。添加了self.clearTopView
视图,并进行了适当的着色。 {EL} tappedViewOverlay
(popoverPresentationController
)按照预期从此视图启动。
问题是视图始终位于屏幕的左上角,而不是所需的位置,即发生点击的位置。这是相关的代码:
thisPPC
有人可以告诉我哪里出错了吗?
修改
CoderWang在我的代码中指出了疏忽,所以我已经纠正了它:
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;
此更改( 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
视图的位置略有变化。您可以在以下屏幕截图中看到它隐藏在“后退”导航按钮后面:
答案 0 :(得分:0)
问题在于' tappedRect'是不正确的,完全不知道原因。 但你可以尝试以下方法来获取" Acct"按钮转换为self.clearTopView:
CGRect tappedRect = [Acct.superview convertRect:acct.frame toView:self.clearTopView];
或转换为窗口(因为self.clearTopView在整个tableview上):
CGRect tappedRect = [Acct.superview convertRect:acct.frame toView:nil];