Iphone 在缩放到新视图时,我想从右视图创建ViewAnimationOptionTransitionFlipFromRight

Iphone 在缩放到新视图时,我想从右视图创建ViewAnimationOptionTransitionFlipFromRight,iphone,ios,objective-c,cocoa-touch,animation,Iphone,Ios,Objective C,Cocoa Touch,Animation,以下是我目前拥有的: 以及其背后的代码: 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 *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];
     }];
 }];
基本上我有一个合理的观点。当点击其中一个视图时,我想同时缩放和翻转它,以便在屏幕中央显示新的更大视图。目前,它会翻转较小的视图,并最终以适当的大小显示较大的视图,但不会平滑过渡

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

非常感谢你的帮助。我对objective c、cocoa touch和执行动画的经验非常有限


非常感谢

看起来您应该使用
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配置适当的自动调整大小选项。)

可以尝试此操作。设置一个视图
containerView
,该视图是
self
的子视图,最初包含smallView。创建最初用于smallView的
containerView
框架。使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];

我只是猜测而已。

我终于猜出来了。请看这里:

它要求我使用View方法执行两个单独的UIView转换:

        [_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];;
        }];

我试过了,但没有成功。您愿意分享一个特定的代码示例吗?具体来说,我想了解如何在视图执行UIViewAnimationOptionTransitionFlipFromRight时缩放和重新定位视图。这就是我被绊倒的地方。我会很感激你的帮助。这似乎让我离你更近了。请看这里:但我仍然错过了smallView上的翻转。不知道为什么。有什么想法吗?看起来containerView正在制作它应该制作的动画,除了smallView会立即消失,而不是制作成largeView的动画。如果你有什么想法,请告诉我。