UIPopoverController在iPad中的位置 [英] position of UIPopoverController in iPad

查看:100
本文介绍了UIPopoverController在iPad中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在按钮点击时打开了一个弹出窗口。

I have opened a pop up window on button click.

我想设置该视图的x和y位置。我已经尝试了很多,但无法正确设置。

I want to set x and y position of that view. I have tried a lot but can't set it properly.

这是我的代码:

-(IBAction)product2_click_h2
{
    //build our custom popover view
    UIViewController* popoverContent2 = [[UIViewController alloc]
                                         init];

    UIView* popoverView2 = [[UIView alloc]initWithFrame:CGRectMake(100,100,200,200)];

    popoverView2.backgroundColor = [UIColor greenColor];

    UITextView *prod2_info = [[UITextView alloc]initWithFrame:CGRectMake(5,5,390,290)];
    [prod2_info setFont:[UIFont fontWithName:@"Arial" size:15]];
    [popoverView2 addSubview:prod2_info];
    [prod2_info setEditable:NO];
    prod2_info.text = @"\n"
    "                    Higher Mileage Motor Oil :\n "
    "                --------------------------------------\n\n"
    "  -->  MaxLife NextGen Higher Mileage Motor Oil  \n\n" 
    "- Special seal conditioners rejuvenate seals\n"
    "   within the engine block to help \n"
    "   prevent oil leaks that lead to sludge and deposits.\n"
    "- Anti-oxidant additives reduce oil viscosity breakdown\n"
    "  to help prevent engine clogging sludge and deposit formation. \n"
    "- Detergents chemically bond with and remove existing\n"
    "  sludge and deposits\n"
    "- Additional friction-reducing additives help reduce abrasion within engine\n"
    "- Anti-wear agents help prevent engine damage \n"
    "- Available in the following viscosity grades \n"
    "    - 5W-30     \n "
    "   - 10W-30    \n ";
    prod2_info.scrollEnabled =YES;
    popoverContent2.view = popoverView2;
    popoverContent2.contentSizeForViewInPopover = CGSizeMake(400,300);

    //create a popover controller
    self.popovercontroller_2 = [[UIPopoverController alloc]
                                initWithContentViewController:popoverContent2];

    //present the popover view non-modal with a
    //refrence to the button pressed within the current view
    [self.popovercontroller_2 presentPopoverFromRect:product2.frame
                                              inView:self.view
                            permittedArrowDirections:UIPopoverArrowDirectionAny
                                            animated:YES];

}

现在看来是这样的:

推荐答案

而不是:

[self.popovercontroller_2 presentPopoverFromRect:product2.frame
                                          inView:self.view
                        permittedArrowDirections:UIPopoverArrowDirectionAny
                                        animated:YES];

只需进行如下更改:

[self.popovercontroller_2 presentPopoverFromRect:product2.frame
                                          inView:**button.bounds**
                        permittedArrowDirections:UIPopoverArrowDirectionAny
                                        animated:YES];

这篇关于UIPopoverController在iPad中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆