简体   繁体   English

ViewControllers之间的转换不起作用

[英]transition between ViewControllers not working

So I got this button that with a if statement that pushes to a the StartViewController . 所以我得到了一个带有if语句的按钮,该语句推送到StartViewController I made a NSLog@"transition successful" in the viewDidLoad of this viewcontroller to check if the transition is made. 我在此viewcontroller的viewDidLoad中创建了一个NSLog@"transition successful" ,以检查是否进行了转换。

In the log its showing the transition successful but on the screen not transition is made. 在日志中它显示转换成功但在屏幕上没有转换。

Here is the code: 这是代码:

-(IBAction)initialButton:(id)sender {
    NSLog(@"initialButton clicked");

   if([userEmail.text length] <4)
   {
       [WCAlertView showAlertWithTitle:@"Email is empty" message:@"You haven't entered an email yet. Please enter one so we can sent you the shipping labels." customizationBlock:^(WCAlertView *alertView) {
           alertView.style = WCAlertViewStyleBlackHatched;
       } completionBlock:^(NSUInteger buttonIndex, WCAlertView *alertView) {
           if (buttonIndex == 0) {
               NSLog(@"Cancel");
           } else {
               NSLog(@"Ok");
           }
       } cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
   }
   else
   {

       StartViewController *startViewController = [[StartViewController alloc] init];
       self.transitionController = [[[TransitionController alloc] initWithViewController:startViewController] initWithNibName:@"StartViewController" bundle:nil];
       [initialViewController.view removeFromSuperview];
       self.window.rootViewController = self.startViewController;

   }


}

and here is the log: 这是日志:

2012-12-14 09:22:55.431 Janssenpakketapp[24165:c07] initialViewController loaded
2012-12-14 09:23:04.021 Janssenpakketapp[24165:c07] initialButton clicked
2012-12-14 09:23:06.116 Janssenpakketapp[24165:c07] Ok
2012-12-14 09:23:11.909 Janssenpakketapp[24165:c07] initialButton clicked
2012-12-14 09:23:11.911 Janssenpakketapp[24165:c07] transition succesful

New update: this should work: 新的更新:这应该工作:

StartViewController *startViewController = [[StartViewController alloc] init];
    [[UIApplication sharedApplication].delegate.transitionController transitionToViewController:startViewController withOptions:UIViewAnimationOptionTransitionFlipFromRight];

you want to to add transition animation then use bellow code... 你想添加过渡动画然后使用下面的代码...

    StartViewController *startViewController = [[StartViewController alloc] init];
    self.window.rootViewController = self.startViewController;
    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];   
    [animation setType:kCATransitionFade];
    [animation setDuration:0.5];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                                  kCAMediaTimingFunctionEaseInEaseOut]];
    [[self.window layer] addAnimation:animation forKey:@"transitionViewAnimation"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM