0

我有 2 个ViewControllers,我创建了一个UIImageView来显示像 iPhone 上的启动画面。我把它写在TestAppDelegate.m

=====================

splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

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

[self.window addSubview:splashScreen];

 sleep(6);

[splashScreen removeFromSuperview];

=====================

我的问题是,

如果我谈到这一点,imageview我会去 2nd ViewController

否则在时间睡眠后,自动到第 1 次ViewController

那么,有可能做到这一点吗?

4

2 回答 2

2

做这个:

在 appDelegate.h 文件中添加 UIGestureRecognizerDelegate。

@interface AppDelegate : UIResponder <UIApplicationDelegate,UIGestureRecognizerDelegate>

现在

splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashScreen.userInteractionEnabled = YES;
splashScreen.image = [UIImage imageNamed:@"Default.png"];
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1;
tapRecognizer.delegate = self;
[splashScreen addGestureRecognizer:tapRecognizer];
[tapRecognizer release];

[self.window addSubview:splashScreen];

sleep(6);
[splashScreen removeFromSuperview];
//add ViewController1 here
ViewController1 *objViewController1 = [[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil];
[self.window addSubview:objViewController1.view];

现在在启动屏幕上点击时将调用处理程序

- (void)handleTap:(UITapGestureRecognizer*)recognizer
{
   // Do Your thing. 
   if (recognizer.state == UIGestureRecognizerStateEnded)
   {
     [splashScreen removeFromSuperview]; //edited here
     ViewController2 *objViewController2 = [[ViewController2 alloc]initWithNibName:@"ViewController2" bundle:nil];
    [self.window addSubview:objViewController2.view];
   }
}
于 2012-09-21T04:45:52.087 回答
0

是的。这是可能的。在 AppDelegate 中保持NSTimer

在计时器的选择器中编写代码以推送到第一个视图控制器。

Touch Recognizer在图像视图和触摸事件上放置一个代码以推送到第二个视图控制器。

于 2012-09-21T04:30:35.513 回答