xcode 如何在ipad中获取指定宽度和高度的弹出框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8292619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:34:15  来源:igfitidea点击:

how to get a popover frame of specified width and height in ipad

iphoneobjective-cxcode

提问by crazy2431

i am using an popover view in my application,when i went through the samples i found how to create a popover view but in the sample code the popover view is getting displayed to whole page. i want the popover frame of specified width and height when i click the button.

我在我的应用程序中使用了弹出视图,当我浏览示例时,我发现了如何创建弹出视图,但在示例代码中,弹出视图显示到整个页面。当我单击按钮时,我想要指定宽度和高度的弹出框。

-(IBAction) settingsGo:(id) sender{

NSLog(@"Go");

if (self.popoverController == nil)

if (self.popoverController == nil)

{
    PopOver *lang = [[PopOver alloc]
                   initWithNibName:@"PopOver" bundle:[NSBundle mainBundle]];

    UIPopoverController *popOver = 
    [[UIPopoverController alloc]initWithContentViewController:lang];

    popOver.delegate = self;
    [lang release];

    self.popoverController = popOver;
    [popOver release];
}



CGRect popoverRect = [self.view convertRect:[button frame]fromView:[button superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 50);

[self. popoverController 
 presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

so what changes i should make in the above code to get a frame of specified size of width and height.

那么我应该在上面的代码中进行哪些更改以获得具有指定宽度和高度大小的框架。

回答by Anil Kothari

Account is the class to be displayed. popAccount is its instance. buttonA is the button on which after click the popOver will be displayed.

Account 是要显示的类。popAccount 是它的实例。buttonA 是单击后将显示 popOver 的按钮。

-(void)viewDidLoad

{
    popAccount = [[Account alloc] init];

        //[popAccount setDelegate:self];

        popOverControllerA = [[UIPopoverController alloc] initWithContentViewController:popAccount];

        popOverControllerA.popoverContentSize = CGSizeMake(200, 200);   

 }   
    -(IBAction)togglePopOverControllerA {

        if ([popOverControllerA isPopoverVisible]) {

            [popOverControllerA dismissPopoverAnimated:YES];

        } else {

            [popOverControllerA presentPopoverFromRect:buttonA.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        }

    }

Further ask for any query..

进一步询问任何查询..

回答by rob mayoff

Set popoverController.popoverContentSizeto whatever size you want.

设置popoverController.popoverContentSize为您想要的任何大小。

回答by dubbeat

In the root view to position

在根视图中定位

CGRect frame= CGRectMake(0,0, 0, 0);

[self.myPickerPopover presentPopoverFromRect:frame inView:self.view permittedArrowDirections:0 animated:NO];

To size in the view controller contents being displayed in the popover

在弹出窗口中显示的视图控制器内容中调整大小

-(void)viewDidLoad

{


  self.contentSizeForViewInPopover = CGSizeMake(750,880);


 }