我想在缩放到新视图的同时将UIViewAnimationOptionTransitionFlipFromRight

时间:2013-05-29 18:34:19

标签: iphone ios objective-c cocoa-touch animation

以下是我目前所拥有的内容:http://cl.ly/PIFB

背后的代码:

UIView *smallView = [[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:recognizer.view.tag inSection:0]] contentView];
CGRect initialSize = smallView.frame;
CGRect finalSize = CGRectMake(150.0, 100.0, 660.0, 450.0);
UIView *largeView = [[UIView alloc] initWithFrame:initialSize];
[largeView setBackgroundColor:[UIColor blackColor]];
[largeView setClipsToBounds:NO];
[UIView transitionFromView:smallView toView:largeView duration:2 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
     [[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:recognizer.view.tag inSection:0]] contentView].frame = finalSize;
     [largeView setFrame:finalSize];
     [smallView removeFromSuperview];
     [self addSubview:largeView];
     [UIView animateWithDuration:2 animations:^{
         smallView.frame = finalSize;
         [largeView setFrame:finalSize];
     }];
 }];

基本上我有一个UITableView视图。当点击其中一个视图时,我想同时缩放和翻转它,以便在屏幕中央显示一个新的更大的视图。目前,它会翻转较小的视图,最终以正确的大小显示较大的视图,但不会平滑过渡。

在上面的代码中,smallView是当前的tapped单元格内容视图。 largeView是最终开发的新视图,用于显示与被挖掘的单元格相关的更多数据。现在它由黑色视图表示。我真的希望小细胞同时生长和翻转,以便它平滑地过渡到更大的视野。

非常感谢您的帮助。我对目标c,可可触摸和表演动画的体验非常有限。

非常感谢。

3 个答案:

答案 0 :(得分:1)

我终于明白了。见这里:http://cl.ly/PQqP

它要求我做两个单独的UIView transitionWithView方法:

        [_transitionView addSubview:smallView];
        [smallView setFrame:CGRectMake(0, 0, _transitionView.frame.size.width, _transitionView.frame.size.height)];
        [UIView transitionWithView:_transitionView duration:.5 options:UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionCurveEaseOut animations:^(){
            [UIView transitionWithView:cellView duration:.25 options:UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionCurveEaseIn animations:^(){
                [cellView setFrame:smallViewOrigin];
            } completion:NULL];
            _transitionView.frame = finalSize;
            smallView.frame = smallViewOrigin;
            [_transitionView insertSubview:metricModalViewController.view belowSubview:smallView];
            [smallView removeFromSuperview];
            metricModalViewController.view.frame = metricModalEndSize;
        } completion:^(BOOL finished) {
            [_transitionView setFinalView:metricModalViewController.view];;
        }];

答案 1 :(得分:0)

看起来您应该使用transitionWithView:duration:options:animations:completion:代替。像这样:

[UIView transitionWithView:self
        duration:2
        options:UIViewAnimationOptionTransitionFlipFromRight|UIViewAnimationOptionAllowAnimatedContent
        animations:^(){
            smallView.frame = finalSize;
            [smallView removeFromSuperview];
            [self addSubview:largeView];
            largeView.frame = finalSize;
        }
        completion:NULL];

这可能会翻转self视图,这可能看起来不太合适。如果这是一个问题,那么在层次结构中添加一个额外的视图,除了包含与它们大小相同的smallView或largeView之外什么都不做。除了smallView和largeView之外,还设置该视图的框架。 (或者只是设置容器视图转换,或者只是设置容器视图框架并为smallView和largeView配置适当的自动调整大小选项。)

答案 2 :(得分:0)

也许试试这个。设置视图containerView,该视图是self的子级,最初包含smallView。使containerView的框架为最初的smallView框架。使smallView的大小与containerView的大小相同,但是原点(0,0)使得smallView完全填充containerView。

[UIView transitionWithView:containerView
        duration:2
        options:UIViewAnimationOptionTransitionFlipFromRight|UIViewAnimationOptionAllowAnimatedContent
        animations:^(){
            containerView.frame = finalSize;
            smallView.frame.size = finalSize.size;
            [smallView removeFromSuperview];
            [containerView addSubview:largeView];
            largeView.frame.size = finalSize.size;
        }
        completion:NULL];

我只是在猜测。