简体   繁体   English

隐藏在另一个视图后面的视图子视图的动画

[英]Animation of a view's subview hiding behind another view

Im trying to animate a UIImage which is a subview of a UIView in the interface builder. 我正在尝试制作一个UIImage动画,该UIImage是界面生成器中UIView的子视图。 My problem is, that this animation goes "through" another view which is the table view and then it simply "goes behind" it and doesn't show all the way. 我的问题是,该动画会“通过”另一个视图(即表格视图),然后仅“落后于”它,而不是一直显示。 My view hierarchy is like this: 我的视图层次结构是这样的:

View
   View
      SubviewToAnimate
   TableView

I have tried [self.view bringViewToFront:SubviewToAnimate] Both in the view itself, and in the animation. 我已经在视图本身和动画中尝试了[self.view bringViewToFront:SubviewToAnimate]

Code for animation: 动画代码:

-(void)startAnimationWithImageView:(UIImageView*)imageView{

    imageViewToMove = imageView;
    imageViewFirstAlpha = imageViewToMove.alpha;

    firstCenterOfView = imageViewToMove.center;

    double firstX =self.parabelWidth*self.startValue;
    double firstY = self.parabelHeight*pow(self.startValue, 2);
    firstPointOfParabel = CGPointMake(firstX, firstY);

    if (points) {
        points = nil;
    }
    points =[[NSMutableArray alloc]init];

    for (int counter = self.startValue; counter < self.stopValue; counter++) {

        double y = self.parabelHeight*pow(counter, 2);
        double x = self.parabelWidth*counter;

        CGPoint point = CGPointMake(x, y);
        [points addObject:[NSValue valueWithCGPoint:point]];
        //DLog(@"point: %@", NSStringFromCGPoint(point));

    }

    animationCounter = 0;
    [self moveView];


}

-(void)moveView{

    if (animationCounter < points.count) {
        [UIView animateWithDuration:self.duration
                              delay:0
                            options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationCurveLinear
                         animations:^{

                             NSValue *val = [points objectAtIndex:animationCounter];
                             CGPoint point = [val CGPointValue];

                             double delta = 1.0/points.count;
                             imageViewToMove.center = CGPointMake(firstCenterOfView.x-firstPointOfParabel.x+point.x, firstCenterOfView.y-firstPointOfParabel.y+point.y);
                             imageViewToMove.alpha = sqrt(imageViewToMove.alpha-delta);

                             double scale = animationCounter*delta;
                             imageViewToMove.transform = CGAffineTransformMakeScale(sqrt(1-scale), sqrt(1-scale));

                             animationCounter++;

                         }
                         completion:^(BOOL finished){

                             [self moveView];

                         }];
    }else if (animationCounter == points.count) {
        imageViewToMove.center = firstCenterOfView;
        imageViewToMove.transform = CGAffineTransformMakeScale(1.0, 1.0);

        [UIView animateWithDuration:0.3
                              delay:0
                            options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationCurveEaseIn
                         animations:^{

                             imageViewToMove.alpha = imageViewFirstAlpha;

                         }
                         completion:NULL];
    }else
        return;


}

You can't use [self.view bringViewToFront:SubviewToAnimate] to put your image view on top of the table view because it isn't a sibling of the table view. 您不能使用[self.view bringViewToFront:SubviewToAnimate]将图像视图放在表格视图之上,因为它不是表格视图的同级。

If you had... 如果你有...

View
    SubView
    ImageView (animated view)
    TableView

Then that code would work. 然后该代码将起作用。

Or, in your current hierarchy, you could bring the SubView to the front which would bring the image view with it. 或者,在您当前的层次结构中,您可以将SubView置于最前面,这将使图像视图随之而来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM