1

我在一些 viewController 视图上有按钮。touchUpInside:方法呈现模态视图控制器。我想从点击按钮框架的中心展示它们。我怎样才能达到这个结果?我试过了:

webController.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, self.buuton.center.x, self.button.center.y);
        [self presentViewController:webController animated:NO completion:^{
            // some code
        }];

但它损坏了我的用户界面。我也试过用[UIView beginAnimation],没有成功。

4

2 回答 2

1

我已经通过一个技巧实现了类似的功能,将 destvc.view 作为子视图添加到 sourcevc.view,请参阅下面我的函数来扩大和扩大规模。

您可以仅将相同的技巧用作视觉效果,并在最后呈现您的 vc,而无需动画:

    +(void) animWithAlpha:(float)alpha view:(UIView*)view{
          [UIView animateWithDuration:0.15
                          delay:0.0
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
                         view.alpha = alpha;
                     }
                     completion:^(BOOL fin) {}];
    }


    +(void) zoomIN:(UIViewController*)sourceViewController destination:(UIViewController*)destinationViewController fromPoint:(CGPoint)point{

        [sourceViewController.view addSubview:destinationViewController.view];
        [destinationViewController.view setFrame:sourceViewController.view.window.frame];
        [destinationViewController.view setTransform:CGAffineTransformMakeScale(0.15, 0.1)];
        destinationViewController.view.center  = point;
        sourceViewController.view.userInteractionEnabled=NO;
        destinationViewController.view.alpha = 0.5;
        [self animWithAlpha:1 view:destinationViewController.view];
        [UIView animateWithDuration:0.4
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             [destinationViewController.view setTransform:CGAffineTransformMakeScale(1, 1)];
                             destinationViewController.view.center  = sourceViewController.view.center;
                         }
                         completion:^(BOOL finished){
                             if(finished){
                                 [destinationViewController.view setTransform:CGAffineTransformMakeScale(1, 1)];
                                 destinationViewController.view.center  = sourceViewController.view.center;
                                 sourceViewController.view.userInteractionEnabled=YES;
                             }
                         }];

    }

    +(void) zoomOUT:(UIViewController*)sourceViewController  destination:(UIView*)destination toPoint:(CGPoint)point{
        [sourceViewController.view setTransform:CGAffineTransformMakeScale(1.0, 1.0)];
        [sourceViewController.parentViewController.view setUserInteractionEnabled:NO];
        [destination setUserInteractionEnabled:NO];
        [UIView animateWithDuration:0.4
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             [sourceViewController.view setTransform:CGAffineTransformMakeScale(0.01, 0.01)];
                             [sourceViewController.view setAlpha:1.0];
                             sourceViewController.view.center  = point;
                         }
                         completion:^(BOOL finished){
                             if(finished){
                                 [sourceViewController.view setTransform:CGAffineTransformMakeScale(1.0, 1.0)];
                                 [sourceViewController.view removeFromSuperview];
                                 sourceViewController.view.center  = point;
                                 [destination setUserInteractionEnabled:YES];
                             }
    }
于 2013-10-04T11:41:41.520 回答
0

您必须通过addSubview:方法并执行以下操作来做到这一点:

- (void) appear: (UIView *) view fromPoint: (CGPoint) point
{
    [view setBounds:self.view.bounds];
    [view setCenter:point];
    [view setAlpha:0.0];
    [self addSubview:view];
    [view setTransform:CGAffineTransformMakeScale(0, 0)];

    [UIView animateWithDuration:0.3 animations:^{
        [view setCenter:self.view.center];
        [view setTransform:CGAffineTransformIdentity];
        [view setAlpha:1.0];
    }];
}

您必须在调用该方法之前创建视图。

祝你好运!

于 2013-10-04T11:39:14.963 回答