-1

我有一个 iPad 应用程序(XCode 4.6、ios 6.2、ARC 和 Storyboards)。我在 UIView 的位置上绘制了一个 GCRect。

    CGRect rectangle = CGRectMake( [appSelected.aPosX floatValue], [appSelected.aPosY floatValue],[appSelected.aPosW floatValue], [appSelected.aPosH floatValue]);

我有一种方法可以为我绘图;这是该方法的代码:

-(void)showHTMLHelp:(NSString *)htmlString pointTo:(id)target background:(UIColor *)bgColor  {

UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 300)];
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0];  //  frame color?
popoverContent.view = popoverView;

//resize the popover view shown in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(200, 300);

//  add the UIWebView for RichText
UIWebView *webView = [[UIWebView alloc] initWithFrame:popoverView.frame];
webView.backgroundColor = [UIColor whiteColor];  //  change background color here

//  add the webView to the popover
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:nil]];
[popoverView addSubview:webView];

//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];

//present the popover view non-modal with a refrence to the button pressed within the current view
if([target isKindOfClass: [UITextField class]])
    [popoverController presentPopoverFromRect:((UITextField *)target).frame inView:self.view
                     permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
else if([target isKindOfClass: [UISegmentedControl class]])
    [popoverController presentPopoverFromRect:((UISegmentedControl *)target).frame inView:self.view
                     permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
else if([target isKindOfClass: [UIButton class]])
    [popoverController presentPopoverFromRect:((UIButton *)target).frame inView:self.view
                     permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
else 
    [popoverController presentPopoverFromRect:*(CGRect *)CFBridgingRetain(target)
                                       inView:self.view
                     permittedArrowDirections:UIPopoverArrowDirectionAny
                                     animated:YES];

}

现在我想让 UIPopover 指向那个矩形。由于 GCRect 是一个 C 结构,我不知道该怎么做。这是我尝试过的,但显然它是错误的。我怎样才能做到这一点?这是我调用该方法以显示弹出框的代码:

    PreferencesViewController *pvc = [[PreferencesViewController alloc] init];
[pvc showHTMLHelp:html pointTo: rectangle background:[UIColor whiteColor]];
4

2 回答 2

1

将 C 结构(或 C 原始变量)传递给 Objective-C 方法绝对没有问题。实际上,presentPopoverFromRect:inView:permittedArrowDirections:animated:您可以通过标题(或文档)告诉您一个简单的 CGRect :

- (void)presentPopoverFromRect:(CGRect)rect 
                        inView:(UIView *)view 
      permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
                      animated:(BOOL)animated;

简单地这样称呼它:

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

正如 Mar0ux 已经指出的那样,它是CGRect,不是GCRectCG代表核心图形

于 2013-05-01T16:19:42.503 回答
0

请问您为什么要发送 CGRect 并将其转换为“id”?哪里来的感悟?!我也希望将您的参数类型更改为 CGRect 。

亲切的问候。

于 2013-05-04T14:44:41.310 回答