ios - 在 Storyboard中为 'tile' 创建更大的翻转 View

标签 ios uiviewcontroller core-animation core-graphics storyboard

我目前有一个容器 View Controller ,它是一个按钮的所在地。当按下此按钮时,我希望 View 翻转并放大,类似于 iPad 上的 iTunes。

主视图 Controller 布局:

enter image description here

翻转容器:

当按下翻转按钮时,我打算使用此代码(在容器 View 的 View Controller 内部)来翻转容器:

FrontVC *cb = [[FrontVC alloc]initWithFrame:CGRectMake(0, 0, 92, 65)];
FlipVC *cf = [[FlipVC alloc]initWithFrame:CGRectMake(0, 0, 92, 65)];

 [UIView transitionWithView:self.view
                  duration:1
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{

                    // Remove last view
                    for (UIView *subview in self.view.subviews) {
                        [subview removeFromSuperview];
                    }
                    [self.view addSubview:(displayingPrimary ? cb: cf)];

                }
                completion:^(BOOL finished) {
                    if (finished) {
                        displayingPrimary = !displayingPrimary;
                    }
                }];

如果两个 View 大小相同,则效果很好,并且我可以使用代码布局 View 。 FrontVC 和 FlipVC 是 UIView 的子类。

我正在考虑做这样的事情来将 View 移动到屏幕中心,但我被困在那里。嘿,我什至不知道这是否有效! 有更好的方法吗?

if (!displayingPrimary) {
                        self.view.center = CGPointMake(320.0f, 480.0f);
                        cb.center = CGPointMake(320.0f, 480.0f);
                    }
                    else
                    {
                        self.view.center = CGPointMake(59, 324);
                    }

我的目标:

理想情况下,我希望能够在 Storyboard 中设计翻转 View ,并使“图 block ”增长,类似于 iTunes:

iTunes Flip

而在我的示例中,我希望它看起来像这样:

My Desired Outcome

我怎样才能在 Storyboard中设计这个?如果我尝试制作一个 View Controller ,我无法将其大小调整为我希望翻转大小 View Controller 的大小.

最佳答案

FlipView项目非常精致,看起来和 iTunes 翻页一模一样。我在演示项目中使用了两个 imageView。实际翻转代码如下:

- (IBAction)flip
{
    UIView *fromView, *toView;
    CGPoint pt;
    CGSize size;
    CGFloat sense;

    if(showingView == a) {
        fromView = a;
        toView = b;
        pt = BORIGIN;
        size = BRECT.size;
        sense = -1;
    } else {
        fromView = b;
        toView = a;
        pt = AORIGIN;
        size = ARECT.size;
        sense = 1;
    }

 [UIView animateWithDuration:TIME/2 animations:^
    {
        CATransform3D t = CATransform3DIdentity;
        t.m34 = M34;
        t = CATransform3DRotate(t, M_PI_2*sense, 0, 1, 0);

        containerView.layer.transform = t;
        containerView.frame = CRECT; // midpoint
        NSLog(@"Container MID Frame %@", NSStringFromCGRect(containerView.frame));
    }
    completion:^(BOOL isFinished)
    {
        toView.layer.transform = CATransform3DMakeRotation(M_PI*sense, 0, 1, 0);
        [UIView animateWithDuration:TIME/2 animations:^
            {
                [fromView removeFromSuperview];
                [containerView addSubview:toView];

                CATransform3D t = CATransform3DIdentity;
                t.m34 = M34;
                t = CATransform3DRotate(t, M_PI*sense, 0, 1, 0);

                containerView.layer.transform = t; //finish the flip
                containerView.frame = (CGRect){ pt, size};
            } completion:^(BOOL isFinished)
            {
                    NSLog(@"Container Frame %@", NSStringFromCGRect(containerView.frame));
                    NSLog(@"A Frame %@", NSStringFromCGRect(b.frame));
                    NSLog(@"B Frame %@", NSStringFromCGRect(b.frame));

                    toView.layer.transform = CATransform3DIdentity;
                    containerView.layer.transform = CATransform3DIdentity;
                    showingView = showingView == a ? b : a;
            }];
    }];

}

http://dl.dropbox.com/u/60414145/FlipView.zip

编辑:解决调整具有实际控件的实际 View 大小的一种方法是拍摄该 View 的快照,在缩放/翻转时使用快照,并在最终完成 block 中切换图像真实的景色。即:

  • 当用户点击图像时创建当前小 View 的 UIImage
  • 创建最终 View 的 UIImage,以其自然大小渲染到上下文中
  • 使用容器 View 中的两个图像来制作动画
  • 在最后的完成 block 中,从 View 中删除 imageView 并将第二个 View 放在 self.view subview 中

关于ios - 在 Storyboard中为 'tile' 创建更大的翻转 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12030888/

相关文章:

ios - 有没有办法知道 iOS 是否以及为什么终止您的应用程序?

ios - 应用程序激活时快速 View 重新加载

ios - 从所有 TableViewCells 获取数据

ios - 通过 UIViewController 传递触摸

ios - 在 Metal 中,经典 Porter-Duff "over"合成的正确混合因子是什么?

iOS:在 UI(子) View 中处理 UIGestureRecognisers

ios - Objective-c 从另一个 View Controller 重新加载 TableView

objective-c - iOS 中的动画背景

ios - UISwitch 在动画 'onTintColor' 时中断开/关动画

cocoa - 简单的CATextLayer缩放问题