gpt4 book ai didi

ios - 弹出 View 的坐标计算

转载 作者:行者123 更新时间:2023-11-28 20:22:23 25 4
gpt4 key购买 nike

在我的应用程序中,一个按钮放置在 View Controller 的底部。单击该按钮时,我需要一个弹出 View ,其中的表格 View 显示在我放置的按钮上方。我的问题是我的弹出 View 的起始位置是我的 View Controller 的顶部。我需要在该按钮上方有一个小的弹出 View 。我使用横向模式。 .

  UIViewController *popoverContent=[[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc]initWithFrame:CGRectMake( 265, 100, 400 , 800)];
popoverView.backgroundColor = [UIColor clearColor];
// popoverView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mmf.png"]];


UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake( 0, 0,400,800) style:UITableViewStylePlain];
table.backgroundColor=[UIColor colorWithRed:(107.0/255.0) green: (164.0/255) blue:(183.0/255) alpha:1];
[table setDataSource:self];
[table setDelegate:self];
[table setRowHeight:80];
[popoverView addSubview:table];

popoverContent.view = popoverView;
// popoverContent.contentSizeForViewInPopover =
//CGSizeMake(250, 665);


self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
[self.popoverController presentPopoverFromRect:popoverView.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popoverController presentPopoverFromRect:CGRectMake( 265,680,400,800)
inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

我尝试了很多坐标值,但它的起始位置不是我想要的。

最佳答案

编辑

    UIViewController *popoverContent=[[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc]initWithFrame:CGRectMake( 0, 0, 400 , 400)];
popoverView.backgroundColor = [UIColor clearColor];
// popoverView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mmf.png"]];


UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake( 0, 0,400,400) style:UITableViewStylePlain];
table.backgroundColor=[UIColor colorWithRed:(107.0/255.0) green: (164.0/255) blue:(183.0/255) alpha:1];
[table setRowHeight:80];
[popoverView addSubview:table];

popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(popoverView.frame.size.width, popoverView.frame.size.width);

UIPopoverController *popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:btnLogin.frame
inView:btnLogin.superview permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

注意您只需确保 按钮的框架 并确保从包含按钮的 View 呈现

关于ios - 弹出 View 的坐标计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15406009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com