0

当我按下按钮时,我想在 UIViewController 中从 UIView 转换到另一个

我写了这段代码:

- (IBAction)changeView:(id)sender {

    CATransition* transition = [CATransition animation];
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    transition.duration = 1.0f;
    transition.type =  @"cube";
    transition.subtype = @"fromTop";
    [self.view1.layer removeAllAnimations];
    [self.view1.layer addAnimation:transition forKey:kCATransition];


}

此代码会将 view1(UIview) 传输到自身。我怎样才能让它过渡到另一个 UIView(例如 view2)。我在哪里可以将另一个 UIview (view2) 放在情节提要中

4

3 回答 3

0

你试过这样吗?

  self.view1.alpha = 0.0;

 [UIView beginAnimations:@"flip" context:nil];

 [UIView setAnimationDelegate:self];

 [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

 [UIView setAnimationDuration:1.0f];

  self.view2.alpha = 1.0;   

  [UIView commitAnimations];
于 2013-07-10T13:07:00.227 回答
0

看看这个代码片段,它更加优雅。还可以查看 Apple 的文档以获取更多花哨的 UIViewAnimationOptions

- (IBAction)changeView:(id)sender
{
    [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        //Remove View-1 from the main view
        [view1 removeFromSuperView];
        //Add the new view to your current view
        [self.view addSubView:view2];
    } completion:^(BOOL finished) {
        //Once animation is complete
    }];
}

确保这两个视图是视图控制器的强属性。

于 2013-07-10T14:01:26.530 回答
0

firstView例如,如果您有两个 UIView secondView,请将其添加到同一矩形上的 UIViewController 中。并将隐藏属性设置为 secondView。

-(IBAction)flipFirstViewToSecondView{
secondView.hidden= NO;
    [UIView transitionWithView:firstView duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{

        [UIView transitionWithView:secondView duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{

        } completion:^(BOOL finished) {
            secondView.hidden = NO;
            firstView.hidden = YES;
        }];

    } completion:^(BOOL finished) {

    }];
}

谢谢。如果您在集成它时遇到任何问题,请告诉我。

于 2013-07-10T14:18:01.757 回答