iOS 在 UIView 上使用部分页面 curl ,而不是 UIViewController

标签 ios animation curl uiview

我有一个包含许多 subview 的 MainViewController。基本上,它分为两个 Pane 。这些 Pane 的设计看起来像剪贴板。我想点击一个按钮,让其中一个剪贴板上的“纸”做部分 curl 以显示下面的页面。

这不是完整的 Modal ViewController 演示情况。

我正在使用以下代码,但结果很奇怪:

    FlipView *flipView = [[FlipView alloc] init];
    [self setFlipView:flipView];
    [flipView setHidden:YES];
    [flipView setFrame:[[self WhereAmI] frame]];
    [[self view] addSubview:flipView];
    [[self view] bringSubviewToFront:[self WhereAmI]];
    [flipView setHidden:NO];
    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setDuration:1.0];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [animation setType:@"pageCurl"];
    [animation setFillMode:kCAFillModeForwards];
    [animation setEndProgress:0.9];
    [animation setRemovedOnCompletion:NO];
    [[self WhereAmI] setHidden:YES];
    [[[self WhereAmI] layer] addAnimation:animation forKey:@"pageCurlAnimation"];

基本上,我尝试以编程方式加载我的新 View ,将其滑入当前可见 View 的后面,然后卷起顶部的 View 以显示现在位于下方的 View 。我得到了一些部分 curl 动画,但 curl 的“页面”不是不透明的,这很奇怪。此外,当我没有将我的 View 和标签设置为隐藏时,即使您看到它们 curl ,您仍然会看到它们“在下面”,这也很奇怪。另外,我没有看到为新 View 放置在 XIB 中的 UILabel。

有什么想法吗?

谢谢!


好的,所以我有一个可行的解决方案,但这并不是我希望做的。我仍然很想找出我最初问题的解决方案,但这是我现在正在做的事情:

  1. 我的“基本” View 的背景图像是一个螺旋装订笔记本的图像。
  2. 所有其他 View 的背景图像是卷页的屏幕截图。 (“背景图像”是指使用 patternImage 创建的 UIColor。)
  3. 转换 View 的代码是:

    - (IBAction)NavigationTabSelected:(id)sender 
    {
        // Flipping views is driven by a SegmentedControl
        int selected = [[self NavigationTabsSegmentedControl] selectedSegmentIndex];
        int current = [[self ViewArray] indexOfObject:[self ActiveFlipView]];
        UIView *newFlip = [[self ViewArray] objectAtIndex:selected];
    
        BOOL up = selected > current;
        [UIView animateWithDuration:1.0
                         animations:^{
                             [UIView setAnimationTransition:(up)?UIViewAnimationTransitionCurlUp:UIViewAnimationTransitionCurlDown forView:[self RightView] cache:YES];
                             [[self ActiveFlipView] removeFromSuperview];
                             [[self RightView] addSubview:newFlip];
                         }
                         completion:^(BOOL finished){
                             [self setActiveFlipView:newFlip];
                         }];
    }
    

如您所见,当前选项卡右侧的选项卡生成“ curl ”,当前选项卡左侧的选项卡生成“向下 curl ”。这不是我想要的,但它符合我的目的。

有什么更好的主意吗?

最佳答案

您是否考虑过将其加载为模态视图?

- (void)yourFrontViewControllerMethod
{
    YourBackViewController *bfvc = [[YourBackViewController alloc] init];
    [bfvc setModalTransitionStyle:UIMoalTransitionStylePartialCurl];
    [self presentViewController:bfvc];
    [bvfc release];
}

这将为您提供一个 View curl 以显示另一个 View 的预期效果。

此外,作为一般经验法则,我们尽量不要以这种方式创建动画。尝试使用基于 block 的方法(例如 [UIView AnimateWithDuration:....]);

希望对您有所帮助:)

关于iOS 在 UIView 上使用部分页面 curl ,而不是 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7799930/

相关文章:

ios - 使用动画将 uitableview 单元移动到顶部

ios - 用macHacha拼零件时解压出错

php - 解析用于与 API 交互的 HTTP 状态代码

http - 多次get参数请求只返回第一个参数

iOS:如何执行大量反向地理编码请求?

android - 如何在 Android 应用程序上创建心电图动画

c# - 如何使用 C# 在 Windows 控制台应用程序中创建 ASCII 动画?

ios - 在 swift (iOS) 中为按钮设置动画时如何移动按钮目标/手势识别器?

php - 查找并替换 Curl 输出 PHP

ios - map 路线 View 未正确显示