iOS UIView动画移动到另一个UIView

时间:2014-06-01 23:23:58

标签: ios animation uiview move

大家好我有2个UIViews。第一个UIView正在通过动画移动,但当它到达第二个UIView时,它会移动到它下面。如何在第二个UIView上移动第一个UIView?

这是我的代码(self.openView是第一个UIView,self.showView是第二个UIView):

- (void)cardImage:(NSString *)cardContent{
    self.cardOpenImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png",cardContent]]];
    self.cardOpenImage.frame = CGRectMake(0, 0, self.openView.frame.size.width, self.openView.frame.size.height);
    UIImageView *cardBacksImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cardbacks.png"]];
    cardBacksImage.frame = CGRectMake(0, 0, self.openView.frame.size.width, self.openView.frame.size.height);
    [self.openView addSubview:cardBacksImage];
    [UIView transitionFromView:cardBacksImage
                        toView:self.cardOpenImage
                        duration:1
                        options:UIViewAnimationOptionTransitionFlipFromRight
                        completion:^(BOOL finished) {
                        [self moveToLeft:nil finished:nil context:nil];

                    }];
}
- (void)moveToLeft:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

    [UIView animateWithDuration:1.0
                          delay:0
                        options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
                     animations:^{
                         [UIView setAnimationDelegate:self];
                         self.openView.center = CGPointMake(247, 180);
                     }
                     completion:^(BOOL finished){
                         NSLog(@"Move to left done");
                     }];

}

1 个答案:

答案 0 :(得分:1)

[self.openView.superview bringSubviewToFront:self.openView];

self.openView置于其超级浏览量视图层次结构的顶部。这将有效,假设您的UIViews都是同一超级视图的子视图。