更改内容大小时UIPopoverController慢动画

时间:2013-11-17 03:42:20

标签: ios ipad animation uipopovercontroller

我有一个UIPopoverController,我在其中推送UiNavigationController,然后根据需要推送后续的视图控制器。如果所有视图的首选内容大小相同但是当UIPopOver需要扩展以支持更大的首选内容大小时动画速度极慢,则此方法很有用。我已经在模拟器和多代iPad上测试了这一切,结果相同,一个2-3秒的动画,而UIPopover扩展视图以支持更大的视图控制器。

如何加快这个动画?

    OTBAddNewClassViewController *addVC = [[OTBAddNewClassViewController alloc]initWithNibName:@"addNewClass" bundle:nil];
    [addVC setPreferredContentSize:CGSizeMake(320, 220)];
    [addVC setDelegate:self];
    UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:addVC];
    self.popVC = [[UIPopoverController alloc]initWithContentViewController:navController];
    [self.popVC setDelegate:self];

    NSInteger popWidth = addVC.view.frame.size.width;
    [self.popVC presentPopoverFromRect:CGRectMake(0, 0, popWidth, addVC.view.frame.size.height) inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

2 个答案:

答案 0 :(得分:7)

您需要设置delegate的{​​{1}},然后覆盖UINavigationController并执行以下操作:

navigationController:willShowViewController:animated:

答案 1 :(得分:1)

更新答案:

要更改UIPopoverController为其contentSize设置动画的速度,请尝试以下操作:

[UIView animateWithDuration:1.0  // Set your desired duration here
                          delay:0.0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{
                         [popoverController setPopoverContentSize:CGSizeMake(width, height)];
                     }
                     completion:^(BOOL finished){

                     }];

原始答案:

如果我正确地关注你,你有一个UIPopoverController包含一个UINavigationController,它可以在popoverController中推送/弹出额外的viewControllers,你希望popOverController根据的大小动态重新调整大小。在push / poppoed viewController中查看。

我在iPad应用程序中实现了类似的功能,我使用以下方法实现了它:

在popoverController中包含的viewController中,我使用contentSizeForPopover属性在viewDidAppear中重新调整popover的大小:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    self.contentSizeForViewInPopover = CGSizeMake(320, 280); // Set your size here.
}

但是,值得注意的是,在iOS 7中不推荐使用contentSizeForViewInPopover,您最终必须更新代码以使popoverController使用setPopoverContentSize更新高度:

    [popoverController setPopoverContentSize:CGSizeMake(320, 280)];

在我的应用程序中,我必须通过设置协议将目标高度传递回我的UIPopoverController来完成此操作。我用以下代码完成了这个:

议定书:

@protocol MyProtocolName <NSObject>

- (void)setPopOverContentSize:(CGSize)size;

我的viewControllers上的委托属性:

@property (nonatomic, assign) id <MyProtocolName> delegate;

viewControllers中的实现:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    ....

    [self.delegate setPopOverContentSize:CGSizeMake(320, 280)];
}

包含符合我创建的协议的popoverController的类:

- (void)setPopOverContentSize:(CGSize)size {
    UINavigationController* navController = (UINavigationController *)self.appPopOver.contentViewController;

    UIViewController* currentViewController = navController.topViewController;
    [myPopoverController setPopoverContentSize:size];
}

您需要自定义我为您的特定课程发布的片段,但我已尝试提供我所遵循的相同过程以达到您想要的效果。

我希望这有帮助!