在自定义segue期间添加子视图不起作用

时间:2014-11-21 17:08:39

标签: ios objective-c

对于类似iOS 7 +的警报视图,我有这个相当不错的自定义警报视图。 Here是源教程。我遇到的唯一问题是添加的影子子视图似乎在iOS 7中不起作用。该问题的根源是在下载的示例项目中,影子添加到UIPresentationController子类中,这样做在iOS 7中不存在,所以我尝试将其移动到动画块中,但是当动画开始时我没有看到视图出现。

这是在iOS 8版本中调用的代码中添加阴影视图的地方:

-(void)presentationTransitionWillBegin
{
    [self decorateView:self.presentedView];

    UIViewController *vc = self.presentingViewController;
    UIView *v = vc.view;
    UIView *con = self.containerView;
    UIView *shadow = [[UIView alloc] initWithFrame:con.bounds];
    shadow.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    shadow.alpha = 0;

    [con insertSubview:shadow atIndex:0];

    shadow.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

    [vc.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
    {
        shadow.alpha = 1;
    }
                                              completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
    {
        v.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
    }];
}

以下是我尝试在iOS 7代码中执行此操作的地方:

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController* vc1 = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController* vc2 = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView* con = [transitionContext containerView];

    UIView* v1 = vc1.view;
    UIView* v2 = vc2.view;


        // presenting
        [con addSubview:v2];


        UIView *shadow = [[UIView alloc] initWithFrame:con.bounds];
        shadow.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
        shadow.alpha = 0;

        [con insertSubview:shadow atIndex:0];

        shadow.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

        CGAffineTransform scale = CGAffineTransformMakeScale(1.6, 1.6);
        v2.transform = scale;
        if ( v1 != nil )
        {
            v2.center = v1.center;
        }
        v2.alpha = 0;

        [UIView animateWithDuration:0.25 animations:^
         {
             shadow.alpha = 1;
             v2.alpha = 1;
             v2.transform = CGAffineTransformIdentity;
         }
                         completion:^(BOOL finished)
         {
             NSLog(@"v2 frame: %@", NSStringFromCGRect(v2.frame));
             [transitionContext completeTransition:YES];
         }];    

以下是差异的几个截图

iOS 7:

enter image description here

iOS 8:

enter image description here

0 个答案:

没有答案