我有2个ViewControllers
,我创建了一个UIImageView
来显示iPhone上的Splash Screen。我在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
,我将转到第二ViewController
。
其他在睡眠后,自动转到第一ViewController
。
那么,有可能这样做吗?
答案 0 :(得分: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];
}
}
答案 1 :(得分:0)
是。这是可能的。在AppDelegate中保留NSTimer
。
在定时器写入代码的选择器中,以推送到第一个视图控制器。
在imageview和touch事件写入代码上放置Touch Recognizer
以推送到第二个视图控制器。