2016-03-28 24 views
2

我想显示一个视图控制器作为UIPopoverPresentationController下面的按钮或在窗口的中心。但它始终显示为完整窗口模式弹出窗口。UIPopoverPresentationController显示全屏幕模式弹出总是

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    MySecondViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"Pop"]; 

    // present the controller 
    // on iPad, this will be a Popover 
    // on iPhone, this will be an action sheet 
    controller.modalPresentationStyle = UINavigationControllerOperationPop; 
    [self presentViewController:controller animated:YES completion:nil]; 
    controller.preferredContentSize = CGSizeMake(280, 230); 
    // configure the Popover presentation controller 
    UIPopoverPresentationController *popController = [controller popoverPresentationController]; 
    popController.permittedArrowDirections = UIPopoverArrowDirectionUp; 
    popController.delegate = self; 

    // in case we don't have a bar button as reference 
    popController.sourceView = self.showPop; 
    popController.sourceRect = CGRectMake(384, -120, 280, 230); 


-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { 
    return UIModalPresentationNone; 
} 

回答

3

试试这个代码,它正在

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
SecondViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"pop"]; 

controller.modalPresentationStyle = UIModalPresentationPopover; 
controller.preferredContentSize = CGSizeMake(280, 230); 
// configure the Popover presentation controller 

controller.popoverPresentationController.delegate = self; 
controller.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp; 


// in case we don't have a bar button as reference 
controller.popoverPresentationController.sourceView = self.view; 
controller.popoverPresentationController.sourceRect = CGRectMake(384, -120, 280, 230); 
// controller.presentationController.delegate = self; 
[self presentViewController:controller animated:YES completion:nil]; 
+0

我要去使用栏按钮......它让我tablewiew上全屏...我应该怎么办?@·哈桑·阿夫塔卜 –

+0

@SurajSukale,它可能是太晚了你,但也许其他人可以从这个评论中受益。您应该将一个委托分配给controller.popoverPresentationController并在委托实现方法'adaptivePresentationStyle(for:UIPresentationController)'中,返回值为'UIModalPresentationStyleNone' – Lukas1

2

我已经发布了同样的问题,另外一个问题,我已经解决了我的问题。这里是问题的链接: UIPopoverPresentationController is showing full screen modal on iPhone

在ViewController.h首先使UIPopoverPresenatationController的属性。

@property(nonatomic,retain)UIPopoverPresentationController *dateTimePopover8; 

然后显示PopOverPresentationcontroller

UINavigationController *destNav = [[UINavigationController alloc] initWithRootViewController:dateVC]; 
/*Here dateVC is controller you want to show in popover*/ 
       dateVC.preferredContentSize = CGSizeMake(280,200); 
       destNav.modalPresentationStyle = UIModalPresentationPopover; 
       _dateTimePopover8 = destNav.popoverPresentationController; 
       _dateTimePopover8.delegate = self; 
       _dateTimePopover8.sourceView = self.view; 
       _dateTimePopover8.sourceRect = [sender frame]; 
       destNav.modalPresentationStyle = UIModalPresentationPopover; 
       destNav.navigationBarHidden = YES; 
       [self presentViewController:destNav animated:YES completion:nil]; 

你一定注意到我们展现的,而不是呈现popOver.So视图控制器,我们必须隐藏在这种新的方式,当我们点击also.It自动隐藏在屏幕上。

-(void)hideIOS8PopOver 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

我们必须在实现文件中实现UIPopoverPresenatationController的委托在实现file.Write委托方法下面。

- (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController: (UIPresentationController *) controller { 
    return UIModalPresentationNone; 
} 
0

在Storyboard中这很容易。只需控制将触发动作(例如UIBarButton或普通按钮)的控件拖放到故事板视图控制器(如果导航控制器的根视图,拖动到导航控制器)。 选择segue并将属性检查器中的Kind改为“Present Modally”,presentation:Form sheet(如果你希望它显示在中间),选择你想要的转换类型(默认为cool)。

Attribute Inspector screenshot

相关问题