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

发布于 2024-12-10 13:43:35 字数 2500 浏览 0 评论 0原文

我有一个具有许多子视图的 MainViewController。基本上,它分为两个窗格。这些窗格的设计看起来像剪贴板。我想按一个按钮,让其中一个剪贴板上的“纸张”部分卷曲以露出下面的页面。

这不是完整的 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"];

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

有什么想法吗?

谢谢!


OK, so I've got a working solution, but it's not quite what I was hoping to do. I'd still love to figure out the solution to my original question, but here's what I'm doing for now:

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

    - (IBAction)NavigationTabSelected:(id)sender 
    {
        // 翻转视图由 SegmentedControl 驱动
        int selected = [[self NavigationTabsSegmentedControl] selectedSegmentIndex];
        int current = [[self ViewArray] indexOfObject:[self ActiveFlipView]];
        UIView *newFlip = [[self ViewArray] objectAtIndex:selected];
    
        BOOL 向上 = 已选择 >当前的;
        [UIView animateWithDuration:1.0
                         动画:^{
                             [UIView setAnimationTransition:(up)?UIViewAnimationTransitionCurlUp:UIViewAnimationTransitionCurlDown forView:[self RightView] 缓存:YES];
                             [[self ActiveFlipView]removeFromSuperview];
                             [[self RightView] addSubview:newFlip];
                         }
                         完成:^(BOOL完成){
                             [自我设置ActiveFlipView:newFlip];
                         }];
    }
    

如您所见,当前选项卡右侧的选项卡生成“向上卷曲”,当前选项卡左侧的选项卡生成“向下卷曲”。这不完全是我想要的,但它达到了我的目的。

还有更好的想法吗?

I've got a MainViewController that has many subViews. Basically, it's broken down into two panes. The panes are designed to look like clipboards. I'd like to hit a button and have the "paper" on one of the clipboards do a partial curl to reveal the page underneath.

This isn't a full Modal ViewController presentation situation.

I'm working with the following code, but the results are funky:

    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"];

Basically, I'm trying to load my new view programmatically, slide it in behind the currently visible view and then curl up the view that's on top to reveal the view that's now underneath. I get somewhat of a partial curl animation, but the "page" that's curling up isn't opaque, which is odd. Also, when I don't set my view and label to be hidden, even though you see them curl up, you also still see them "underneath", which is also odd. Plus, I don't see the UILabel I placed in the XIB for the new view.

Any thoughts?

Thanks!


OK, so I've got a working solution, but it's not quite what I was hoping to do. I'd still love to figure out the solution to my original question, but here's what I'm doing for now:

  1. The background image for my "base" view is an image of a spiral-bound notebook.
  2. The background image for all other views is a screen shot of a page curl.
    (By "background image", I mean a UIColor created with a patternImage.)
  3. The code to transition views is:

    - (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];
                         }];
    }
    

As you can see, tabs to the right of the current tab generate a "curl up" and tabs to the left of the current tab generate a "curl down". It's not quite what I wanted, but it serves my purpose.

Any better ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

任谁 2024-12-17 13:43:35

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

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

这将为您提供所需的视图卷曲以显示另一个视图的效果。

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

希望有帮助:)

have you considered loading it as a modal view?

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

This will give you the desired effect of a view curling up to reveal another view.

Also as a general rule of thumb we try not to create animations that way. Try using a block based method instead (eg [UIView AnimateWithDuration:....]);

Hope that helps :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文