ios - 动画结束后设置新的 Controller

标签 ios objective-c uinavigationcontroller

当应用程序启动时,第一个 SplashScreen 正在显示并且它用于启动画面(用于动画目的)当动画完成时它应该被推送到另一个 MainViewController . 任何人都可以告诉我我的代码错误在哪里或者我该如何解决这个问题。

这是我的 .h 文件

#import <UIKit/UIKit.h>
#import "SplashScreen.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    UIImageView *splashView;
    }
@property (strong, nonatomic) UIWindow *window;

@end

这是我的 .m 文件

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    [_window addSubview:obj_SplashViewController.view];
    [_window makeKeyAndVisible];


    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,480, 320, 50)];
    splashView.image = [UIImage imageNamed:@"icon_offer.PNG"];
    [_window addSubview:splashView];
    [_window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:4.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    splashView.alpha = 0.0;
    splashView.frame = CGRectMake(0, 100, 320, 50);
    [UIView commitAnimations];

    return YES;
}




- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [splashView removeFromSuperview];
    MainViewController *obj_MainViewController = [[MainViewController alloc]init];
    [self.window setRootViewController:obj_MainViewController];
}

最佳答案

尝试使用 Animation Block for iOS 4 and later :

  [UIView animateWithDuration:.3
                         animations:^{
                         splashView.alpha = 0.0;
                         splashView.frame = CGRectMake(0, 100, 320, 50);
                         }
                         completion:^(BOOL finished){
                             NSLog(@"completion block");
                              [splashView removeFromSuperview];
                               MainViewController *obj_MainViewController = [[MainViewController alloc]init];
                              [self.window setRootViewController:obj_MainViewController];
                         }];
    }

关于ios - 动画结束后设置新的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24736955/

相关文章:

objective-c - 在没有 UIWebView 的情况下打开 URL 以在服务器上启动进程

ios - 查看旧导航栏和选项卡栏 Controller 的 Controller 问题

ios - 需要一个 UINavigationController 的解决方案,带有应用程序的后退按钮

ios - 自定义顶部导航栏

iphone - 制作一个跨 View Controller 重复的函数 DRY

iphone - 如何在没有 wifi 和 3g 的情况下将推送通知传递到 iOS 设备?

ios - 如何将加速度计g力值转换为度

ios - 以编程方式为所有 UISlider 分配默认操作

ios - 如何在另一个 View iOS 上垂直翻转 View ?

iphone - 选择时自定义子类 UITableViewCell 的属性