0

在 IOS 6 之前,我使用以下代码来呈现具有自定义大小的模态视图:

- (void) showModalViewWithController:(GUIViewController*) _viewController {
    [UIView beginAnimations:@"" context:nil];
    [self presentModalViewController:_viewController animated:YES];
    _viewController.view.superview.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    _viewController.view.superview.frame = CGRectMake(
        _viewController.view.superview.frame.origin.x,
        _viewController.view.superview.frame.origin.y,
        700.0f,
        self.view.frame.size.height - 80.f);
    _viewController.view.superview.center = self.view.center;

    [UIView commitAnimations];
}

现在我必须更改功能

- (void)presentModalViewController: (UIViewController *)viewControllerToPresent animated:(BOOL)flag

- (void)presentViewController: (UIViewController *)viewControllerToPresent animated: (BOOL)flag completion: (void (^)(void))completion

不幸的是,在这样的更改之后调整大小效果不佳:

- (void) showModalViewWithController:(GUIViewController*) _viewController {
    [self presentViewController:_viewController animated:YES completion:^(){
        [UIView beginAnimations:@"" context:nil];
        _viewController.view.superview.autoresizingMask = UIViewAutoresizingFlexibleHeight;
        _viewController.view.superview.frame = CGRectMake(
            _viewController.view.superview.frame.origin.x,
            _viewController.view.superview.frame.origin.y,
            700.0f,
            self.view.frame.size.height - 80.f);
        _viewController.view.superview.center = self.view.center;
        [UIView commitAnimations];
    }];
}

因为模态视图在它的框架操作之前呈现并且它在调用完成块之后跳转。

如何处理?

提前致谢,

米哈乌

4

2 回答 2

0

我不确定为什么完成块动画会跳转。我从来没有使用过这种[UIView beginAnimations:context:]方法。我通常将基于块的动画方法称为[UIView animateWithDuration:animations:completion:]. 这是因为在 iOS 4 及更高版本中不鼓励使用 beginAnimations 方法。

我会尝试更改您的动画以使用基于块的方法。提交动画后,可能会出现一些奇怪的线程问题。

我发现您在显示视图调整视图大小而不是事先调整大小,这很有趣。

于 2012-10-27T02:05:18.427 回答
0

AHKNavigationController *navigationController = [[AHKNavigationController alloc] initWithRootViewController:moreOverView];

[navigationController setModalPresentationStyle:UIModalPresentationFormSheet];

    navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    navigationController.navigationBarHidden=YES;
    if([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0)
    {
        [self presentViewController:navigationController animated:YES completion:^{
            [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                    //Make the modal bigger than normal
                navigationController.view.superview.frame = CGRectMake(
                                                                       navigationController.view.superview.frame.origin.x,
                                                                       navigationController.view.superview.frame.origin.y,
                                                                       540,
                                                                       622
                                                                       );
            } completion:^(BOOL finished) {
            }];
        }];
    }
    else{
        [self presentViewController:navigationController animated:YES completion:nil];
        navigationController.preferredContentSize = CGSizeMake(540,622);
        navigationController.view.superview.center = self.view.center;
    }
    navigationController.view.superview.autoresizingMask =
    UIViewAutoresizingFlexibleTopMargin |
    UIViewAutoresizingFlexibleBottomMargin;

AHKNavigationController 位于https://github.com/fastred/AHKNavigationController

于 2015-06-29T12:49:51.207 回答