1

我想从弹出视图返回主视图,我向你解释

-(void)tapAction1:(UITapGestureRecognizer*) sender
{

Clicked = sender.view.tag-500;
DemoViewController *sign = [[DemoViewController alloc]initWithNibName:@"DemoViewController" bundle:nil];


[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

UIViewController* popoverContent = [[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc]
                       initWithFrame:CGRectMake(0, 0,  100,  sign.view.frame.size.height)];
popoverView.backgroundColor = [UIColor clearColor];
popoverContent.view = popoverView;
    [popoverView addSubview: sign.view];

//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake( sign.view.frame.size.width, sign.view.frame.size.height);

//create a popover controller
UIPopoverController* popover = [[UIPopoverController alloc]
                                initWithContentViewController:popoverContent];
CGRect popoverRect = [self.view convertRect:[sender.view frame]
                                   fromView:[sender.view superview]];

popoverRect.size.width = MIN(popoverRect.size.width, 500);
popoverRect.origin.x  = popoverRect.origin.x;
//popoverRect.size.height  = ; 
//present the popover view non-modal with a
//refrence to the toolbar button which was pressed
[popover presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

//release the popover content
[popoverView release];
[popoverContent release]; 
//[[self view] addSubview:sign.view];

[UIView commitAnimations];

}

现在在 demoviewcontroller 中是一个 xib。我想在其中放置一个名为 close 的按钮,并且我想关闭此弹出窗口。

4

2 回答 2

1

在 DemoViewController 中添加按钮,如下所示:

UIButton *btnClose = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnClose addFrame:CGRectMake(20,20,80,30)];
[btnClose setTitle:@"Close" forState:UIControlStateNormal];
[btnClose addTarget:self action:@selector(dissmissPopOver:) forControlEvents:UIControlEventTouchUpInside];
[sign addSubView:btnClose];

现在选择器是:

- (void)dissmissPopOver:(id)sender
{
  [popover dismissPopoverAnimated:YES];
}
于 2012-08-28T11:02:44.937 回答
1

我会UIPopoverController* popoverDemoViewController.

@property (nonatomic, strong) UIPopoverController* popover;

然后,您可以将在您发布的代码中分配的弹出框传递给此类:

sign.popover = popover;

将此选择器添加到 DemoViewController

- (IBAction) didClickDismissPopoverButton:(id)sender
{
    [self.popover dismissPopoverAnimated:YES];
}

然后只需将此 IBAction 与 Interface Builder 中的 UIButton Touch Up Inside 事件连接起来。

于 2012-08-28T10:32:02.303 回答