2012-08-01 77 views
0

我在按鈕單擊時打開了一個彈出窗口。UIPopoverController在iPad中的位置

我想設置該視圖的x和y位置。我嘗試了很多,但無法正確設置。

這是我的代碼:

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

} 

下面是它看起來像現在:

enter image description here

+0

非常感謝編輯 – 2012-08-01 11:22:33

+0

不客氣。標題說「大小」,但它聽起來像你想控制的位置,對吧? 'product2'究竟是什麼,它在視圖中的位置? – Anna 2012-08-01 11:32:41

+0

是的right..product 2在按鈕名稱...在這裏我設置了圖像按鈕和按鈕單擊,我想打開彈出窗口...但我不能設置位置。所以當我點擊圖像..波普應該打開附近的圖像(按鈕) – 2012-08-01 11:41:56

回答

0

,而不是這樣的:

[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]; 
+0

product2是我的按鈕名稱..... – 2012-08-03 05:49:24

+0

確定只要將它按鈕名稱給inView。 :] – Nayan 2012-08-03 05:54:00

+0

** ** button.bounds正顯示出我錯誤 – 2012-08-03 05:54:58

相關問題