0

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

  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];

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

4

4 回答 4

2

编辑

    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];

注意 您只需确定frame of your button并确保从view that contains button

于 2013-03-14T10:21:25.083 回答
1

试试这个对你有帮助

UIViewController* popoverContent = [[UIViewController alloc] init];
        UIView*   popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 400, 320, 260)];
        popoverView.backgroundColor = [UIColor whiteColor];

        UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake( 0, 0,320,260) 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;
        popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
        popoverRect = CGRectMake(100, 200, 1,30);

      //    in the above line change the position of the popover controller 

        popoverController.popoverContentSize = CGSizeMake(320, 260);
        [popoverController 
         presentPopoverFromRect:popoverRect
         inView:self.view
         permittedArrowDirections:UIPopoverArrowDirectionUp
         animated:YES];
于 2013-03-14T10:47:14.383 回答
0

突然出现 popOver 并不是一个好主意。当它从 UI 控件呈现时,对用户来说更容易。

但是尝试在 UIView 和您的 TableView 的 ViewDidLoad 中设置 contentPopOverSize。

[self setContentSizeForViewInPopover:CGSizeMake(width, height)];

您在 CGRectMake 中给出的框架应该与您的按钮相关。

希望能帮助到你。

于 2013-03-14T10:13:15.780 回答
0

presentPopoverFromRect是弹出框将指向的矩形

[self.popoverController presentPopoverFromRect:yourBtn.frame inView:self.view    permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

请记住,yourBtn 的框架是根据 viewcontroller 的视图计算的,如果您的按钮位于任何其他视图内,那么它将根据该视图计算其坐标,并且定位将不正确。

于 2013-03-14T10:47:25.820 回答