gpt4 book ai didi

iphone - 从 default@2x.png 到 MainView 的过渡

转载 作者:行者123 更新时间:2023-11-29 11:11:48 25 4
gpt4 key购买 nike

总的来说,我对 Objective-C 和 iOS 开发还比较陌生,如果对我的问题有任何帮助和指导,我将不胜感激。

我已经编写了我的第一个应用程序,它是一个具有主视图和翻转 View 的“实用程序”应用程序。该应用程序在模拟器和我的 iPhone 上都按预期工作。但是,从 Default.png 图像到我的主视图有一个明显的突然变化。

我遵循了来自 https://stackoverflow.com/a/9918650/1324822 的 n13 建议代码,但是,我得到的只是主视图,然后淡入黑色。

我在 AppDelegate.m 文件中的代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// set up your root view and stuff....
//.....(do whatever else you need to do)...

// show the main window, overlay with splash screen + alpha dissolve...
UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
[self.window addSubview:splashScreen];
[self.window makeKeyAndVisible];

[UIView animateWithDuration:0.3 animations:^{splashScreen.alpha = 0.0;}
completion:(void (^)(BOOL)) ^{
[splashScreen removeFromSuperview];
}
];
return YES;
}

我承认我在项目的这一部分“即兴发挥”,尽管我非常想知道是什么导致了这个问题,以及如何解决它。我希望我需要在上面的某个地方指定我的 mainView,也许像评论那样初始化它,但我不确定如何做到这一点,因为没有转换唯一的要求是设置 return YES;

如果有帮助,这是一个 Storyboard项目。我正在运行 Xcode 4.3.3。

再次感谢。

最佳答案

这是我制作闪屏的方式:

我没有将它放入 App Delegate,而是放在查看的第一个屏幕上。你所需要的只是你的 rootViewController 中的两个实例变量,第一个是 UIView *black,第二个是 UIImageView *splash。然后:

-(void) viewWillAppear:(BOOL)animated {

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{

self.view.userInteractionEnabled = NO;
black = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
black.backgroundColor = [UIColor blackColor];


splash = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[splash addSubview:indicator];
indicator.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, 455);

[indicator startAnimating];
//the indicator part is arbitrary, of course

splash.image = [UIImage imageNamed:@"Default.png"];

[self.view addSubview:black];
[self.view addSubview:splash];

});


}

然后:

-(void) viewDidAppear:(BOOL)animated {

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{



[UIView animateWithDuration:0.4 delay:2 options:UIViewAnimationCurveEaseInOut animations:^{
splash.alpha=0;
} completion:^(BOOL finished) {
[splash removeFromSuperview];

[UIView animateWithDuration:0.45 delay:0.2 options:UIViewAnimationCurveEaseInOut animations:^{
black.alpha = 0;
} completion:^(BOOL finished) {
[black removeFromSuperview];
black = nil;
splash = nil;
self.view.userInteractionEnabled = YES;

}];
}];

});


}

我没有使用具有导航 Controller 或选项卡 View Controller 的应用程序测试此代码,但它与常规 View Controller 一起工作就像一个魅力。

关于iphone - 从 default@2x.png 到 MainView 的过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11250455/

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