0

我正在使用 Apple 开发网站上的 PageControl 项目。我在项目中添加了一个翻转视图,并在每个视图/页面的右上角添加了一个信息图标。出于某种原因,只有第一页能够为翻转设置动画。第 2 页仍然显示翻页,但没有动画。为了确保第 1 页没有什么特别之处,我切换了第 1 页和第 2 页,效果很好。位置 1 的第 2 页动画,而位置 2 的第 1 页没有动画。任何想法为什么会发生这种情况或我如何解决它?

我确实看过这个帖子,这似乎是同一个问题:Flip View Iphone。但是,我的翻转视图是一个 UIViewController,上面带有信息图标的类也是如此。在另一个线程中,他们正在使用 UIViews。

我确实从上面的线程中实现了 showInfo 代码。在第 2 页时,我看不到翻转。然后我滚动到第 1 页,看到它已经翻转。不知道为什么它不留在第 2 页。在第 1 页时,它不会为翻转设置动画。翻转视图突然出现。

4

1 回答 1

1

你有容器视图吗?可以在那里添加和删除子视图的东西吗?如果你有两个 viewController,一个来一个去,没有 containerView,动画可能会中断。我使用 rootViewController 并在后面使用 rootViewcontroller 为我的所有页面设置动画。这是我的翻转代码,您可能需要进行一些编辑才能使其适合您:

(请记住,self 是 rootViewcontroller,一个带有空白视图的视图控制器(为它着色,使其与您的视图相匹配))

- (void)switchTwoViews:(UIViewController *)view1 otherView:(UIViewController *)view2
{
    /*
     This method is called to switch views.
     It flips the displayed view from the main view to the flipside view and vice-versa.
     */

    UIViewController *coming = nil;
    UIViewController *going = nil;
    UIViewAnimationTransition transition;

    [view1.view setUserInteractionEnabled: NO];
    [view2.view setUserInteractionEnabled: NO];
    if (view1.view.superview == nil) {
        coming = view1;
        going = view2;
        transition = UIViewAnimationTransitionFlipFromLeft;
    }
    else {
        coming = view2;
        going = view1;
        transition = UIViewAnimationTransitionFlipFromRight;
    }
        // in some cases the following is needed to size the view
    //  coming.view.frame = [UIScreen mainScreen].applicationFrame;

    //  going.view.alpha = 1.0;     //uncomment these lines if we want fading of views
    //  coming.view.alpha = 0.0;

    NSArray *viewArray = [[NSArray alloc] initWithObjects:coming, going, nil];
    [coming viewWillAppear:YES];
    [going viewWillDisappear:YES];
    [UIView beginAnimations:@"View Flip" context:viewArray]; {
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationDidEnd:finished:context:)];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

        //      coming.view.alpha = 1.0;        //uncomment these lines if we want fading of views
        //      going.view.alpha = 0.0;

        [UIView setAnimationTransition:transition forView:self.view cache:YES];
        [self.view addSubview: coming.view];
    }
    [UIView commitAnimations];

}

- (void) animationDidEnd:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    NSArray *viewArray = context;
    [((UIViewController *)[viewArray objectAtIndex:1]).view removeFromSuperview];
    [[viewArray objectAtIndex:1] viewDidDisappear:YES];
    [[viewArray objectAtIndex:0] viewDidAppear:YES];
    [[[viewArray objectAtIndex:0] view] setUserInteractionEnabled: YES];
    [viewArray release];
}
于 2009-11-01T08:50:03.587 回答