gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:02:41 24 4
gpt4 key购买 nike

当应用程序启动时,第一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com